我正试图在swift中对我的mac上的文本进行演讲。我发现了一些文章,但它们都是针对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中使用?在游乐场有可能吗?
提前致谢, Jersh
答案 0 :(得分:3)
似乎Speech library仅适用于iOS,因此您对SFSpeechRecognizer感到不满意。 NSSpeechRecognizer
可能是另一种选择,但要求您提供一个单词列表供其识别(而不是从任意单词中识别)。