UIButton subclass with push to talk recording, speech recognition and Siri-style waveform view.
SpeechRecognizerButton is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SpeechRecognizerButton'
Or you can install it with Carthage:
github "alexruperez/SpeechRecognizerButton"
Or install it with Swift Package Manager:
dependencies: [
.package(url: "https://github.com/alexruperez/SpeechRecognizerButton.git")
]
Add NSMicrophoneUsageDescription
and NSSpeechRecognitionUsageDescription
keys to your Info.plist
file containing a description of how your app will use the voice recording and speech recognition.
button.authorizationErrorHandling = .openSettings(completion: ...)
button.authorizationErrorHandling = .custom(handler: { error in
// TODO: Your code here!
})
button.resultHandler = { recordURL, speechRecognitionResult in
// TODO: Your code here!
}
button.errorHandler = { error in
// TODO: Your code here!
}
Just set weak var waveformView: SFWaveformView?
property or use the Interface Builder outlet.
Just set weak var activityIndicatorView: UIActivityIndicatorView?
property or use the Interface Builder outlet.
Just set the following properties by code or use the Interface Builder inspectables.
button.audioSession...
button.recordURL = ...
button.audioFormatSettings = [AV...Key: ...]
button.maxDuration = ...
button.locale = Locale....
button.taskHint = SFSpeechRecognitionTaskHint....
button.queue = OperationQueue....
button.contextualStrings = ["..."]
button.interactionIdentifier = "..."
button.animationDuration = ...
button.shouldVibrate = ...
button.shouldSound = ...
button.pushToTalk = ...
button.speechRecognition = ...
button.cancelOnDrag = ...
button.shouldHideWaveform = ...
button.cornerRadius = ...
button.borderColor = ...
button.borderWidth = ...
button.selectedColor = ...
button.highlightedColor = ...
button.disabledColor = ...
button.highlightedAlpha = ...
Just set the following properties by code or use the Interface Builder inspectables.
waveformView.waveColor = ...
waveformView.numberOfWaves = ...
waveformView.primaryWaveLineWidth = ...
waveformView.secondaryWaveLineWidth = ...
waveformView.idleAmplitude = ...
waveformView.frequency = ...
waveformView.density = ...
waveformView.phaseShift = ...
waveformView.amplitude = ...
- SFWaveformView based on jyunderwood/WaveformView-iOS, thanks!
- Contributions are very welcome.
- Attribution is appreciated (let's spread the word!), but not mandatory.
alexruperez, [email protected]
SpeechRecognizerButton is available under the MIT license. See the LICENSE file for more info.