Swiftpack.co - iOSDigital/STTLibrary as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by iOSDigital.
iOSDigital/STTLibrary 1.1.1
A quick and easy way to leverage SFSpeechRecognizer
⭐️ 1
🕓 3 years ago
iOS macOS
.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 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

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