A simple Swift package wrapper for SFSpeechRecognizer. Returns a string.
Using Swift Package Manager, in Xcode:
https://github.com/iOSDigital/STTLibrary.git
Just drop SSTLibrary.swift into your project.
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()
STTLibrary is licensed under the MIT License.
link |
Stars: 1 |
Last commit: 3 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics