SpeechRecognizerButton 0.2.0

SpeechRecognizerButton 0.2.0

alexruperez 维护。



SpeechRecognizerButton

Twitter Version License Platform Swift Build Status Carthage compatible Swift Package Manager Compatible

一个按钮子类,具有点击说话录音、语音识别和 Siri 风格的波纹视图。

SpeechRecognizerButton

📲安装

SpeechRecognizerButton 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中

pod 'SpeechRecognizerButton'

或者您可以使用 Carthage 安装它

github "alexruperez/SpeechRecognizerButton"

或者使用 Swift 包管理器 安装它

dependencies: [
    .package(url: "https://github.com/alexruperez/SpeechRecognizerButton.git")
]

🐒用法

配置

NSMicrophoneUsageDescriptionNSSpeechRecognitionUsageDescription 键添加到您的 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 = ...

❤️等等。

👨‍💻作者

alexruperez[email protected]

👮‍♂️ 许可证

SpeechRecognizerButton 使用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。