我正在尝试在我的mac上用swift实现语音到文本的转换。我找到了一些文章,但它们都是针对iOS的。我正在尝试跟随这篇文章:http://www.appcoda.com/siri-speech-framework/
到目前为止,这是我的代码在Playground:
//: Playground - noun: a place where people can play
import Cocoa
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
import Speech
while true {
microphoneButton.isEnabled = false //2
speechRecognizer.delegate = self //3
SFSpeechRecognizer.requestAuthorization { (authStatus) in //4
var isButtonEnabled = false
switch authStatus { //5
case .authorized:
isButtonEnabled = true
case .denied:
isButtonEnabled = false
print("User denied access to speech recognition")
case .restricted:
isButtonEnabled = false
print("Speech recognition restricted on this device")
case .notDetermined:
isButtonEnabled = false
print("Speech recognition not yet authorized")
}
OperationQueue.main.addOperation() {
self.microphoneButton.isEnabled = isButtonEnabled
}
}
}
出现错误“无此类模块语音”
我的问题是,这在macOS中可能吗?在Playground中可能吗?
先谢谢你了,杰什
2条答案
按热度按时间g9icjywg1#
看起来Speech library只在iOS上可用,所以你在SFSpeechRecognizer上运气不好。
NSSpeechRecognizer
可能是一个替代方案,但需要你给予一个单词列表,以便它识别(而不是识别任何任意单词)。nhaq1z212#
这是我在MacOS上搜索声转文的第一批结果之一。但可接受的答案似乎已经过时,而且MacOS 10.15+现在支持Speech框架。以下是Apple的Speech框架主页,表明它支持Mac:https://developer.apple.com/documentation/speech
“识别实时音频中的语音”链接会将您带到一个特定于iOS的示例。但是,转到SFSpeechRecognizer类页面会列出在任何支持的平台上设置它所需的步骤:https://developer.apple.com/documentation/speech/sfspeechrecognizer
对于处理实时音频位,建议使用此对象:https://developer.apple.com/documentation/speech/sfspeechaudiobufferrecognitionrequest
关于这个的文档似乎没有涉及捕获音频流。我发现这个用于捕获所需PCM格式的音频流:https://developer.apple.com/documentation/soundanalysis/classifying_sounds_in_an_audio_stream
希望这足以给人们指出正确的方向,但当我设置一个工作代码示例时,我会更新这个答案。