语音转文本 macOS swift playground
speech to text macOS swift playground
我正在尝试在 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
}
}
}
报错,"No such Module Speech"
我的问题是,在 macOS 中是否可行?在操场上可以吗?
提前致谢,
杰什
Speech library 似乎仅在 iOS 上可用,因此您对 SFSpeechRecognizer 的运气不佳。 NSSpeechRecognizer
可能是一个替代方案,但需要您提供一个单词列表以供其识别(而不是从任意单词识别)。
我正在尝试在 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
}
}
}
报错,"No such Module Speech"
我的问题是,在 macOS 中是否可行?在操场上可以吗?
提前致谢, 杰什
Speech library 似乎仅在 iOS 上可用,因此您对 SFSpeechRecognizer 的运气不佳。 NSSpeechRecognizer
可能是一个替代方案,但需要您提供一个单词列表以供其识别(而不是从任意单词识别)。