Swiftpack.co -  iOSDigital/STTLibrary as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
iOSDigital/STTLibrary
A quick and easy way to leverage SFSpeechRecognizer
.package(url: "https://github.com/iOSDigital/STTLibrary.git", from: "1.1.1")

STTLibrary

Overview

A simple Swift package wrapper for SFSpeechRecognizer. Returns a string.

Installation

Using Swift Package Manager, in Xcode:

File > Swift Packages > Add Package Dependency

https://github.com/iOSDigital/STTLibrary.git

Or manually

Just drop SSTLibrary.swift into your project.

Requirements

  • Swift 5
  • iOS 13+
  • macOS 10.15+
  • Untested on tvOS, might work!

Usage

Firstly, before you do anything, add the Microphone and Speech privacy entries into your app's info.plist, otherwise it will hard crash!

<key>NSSpeechRecognitionUsageDescription</key>
<string>Need speech</string>
<key>NSMicrophoneUsageDescription</key>
<string>Need microphone</string>

Then, once you have imported the module:

import SSTLibrary

Create a global instance of the Shared Instance:

let sstManager = SSTLibrary.shared

On say, a button press, start the recognizing process:

sstManager.startRecognizing { (result) in
    switch result {
        case .success(let string):
            // This is your speech to text result!
            print(string)

        case .failure(let error):
            // Something went wrong :(
            print("Error: \(error)")
    }
}

The completion block above will be called once you call stopRecognizing, say when you press another button:

sstManager.stopRecording()

Licence

STTLibrary is licensed under the MIT License.

GitHub

link
Stars: 1
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API