SpeechRecognizerButton
一个按钮子类,具有点击说话录音、语音识别和 Siri 风格的波纹视图。
📲 安装
SpeechRecognizerButton 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中
pod 'SpeechRecognizerButton'
Carthage 安装它
或者您可以使用github "alexruperez/SpeechRecognizerButton"
Swift 包管理器 安装它
或者使用dependencies: [
.package(url: "https://github.com/alexruperez/SpeechRecognizerButton.git")
]
🐒 用法
配置
将 NSMicrophoneUsageDescription
和 NSSpeechRecognitionUsageDescription
键添加到您的 Info.plist
文件中,其中包含您的应用如何使用语音录音和语音识别的描述。
处理授权
拒绝权限时自动打开设置
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!
}
分配波形视图
只需设置 weak var waveformView: SFWaveformView?
属性或使用 Interface Builder 的出口。
分配活动指示器视图
只需设置 weak var activityIndicatorView: UIActivityIndicatorView?
属性或使用 Interface Builder 的出口。
自定义 SFButton 配置
只需通过代码设置以下属性或使用界面构建器的可检查属性。
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 = ...
自定义 SFWaveformView 配置
只需通过代码设置以下属性或使用界面构建器的可检查属性。
waveformView.waveColor = ...
waveformView.numberOfWaves = ...
waveformView.primaryWaveLineWidth = ...
waveformView.secondaryWaveLineWidth = ...
waveformView.idleAmplitude = ...
waveformView.frequency = ...
waveformView.density = ...
waveformView.phaseShift = ...
waveformView.amplitude = ...
❤️ 等等。
- SFWaveformView 基于 jyunderwood/WaveformView-iOS,感谢!
- 欢迎投稿。
- 赞赏引用(让我们广为传播!)是受欢迎的,但不是强制性的。
👨💻 作者
👮♂ ️ 许可证
SpeechRecognizerButton 使用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。