【发布时间】:2019-05-20 22:07:23
【问题描述】:
我尝试设置一个按钮来对标签中的文本进行语音(使用不同的声音/语言),但是当有运算符符号(+、-、×)时语音效果不佳,任何解决此问题的想法有问题吗?
我试过了:
//Option 1
TextLabel.text = "1 + 2 - 3 × 4" // Result: "+" = "and" other voice "plus" (ok), "-" = mute, "×" = mute, other voice "X" (letter)
//Option 2
TextLabel.text = "1 ➕ 2 ➖ 3 ✖️ 4" // Result: "+" = plus symbol, "-" = minus symbol, "×" = multiplication symbol
import UIKit
import AVFoundation
import Speech
class ViewController: UIViewController {
let synth = AVSpeechSynthesizer()
@IBAction func speaker(_ sender: UIButton) {
if (!synth.isSpeaking) {
let speech = AVSpeechUtterance(string: TextLabel.text!)
speech.voice = AVSpeechSynthesisVoice(language: "en-US")
speech.rate = 0.5
speech.pitchMultiplier = 1
speech.volume = 1
synth.speak(speech)
}
}
@IBOutlet weak var TextLabel: UILabel!
//Option 1
TextLabel.text = "1 + 2 - 3 × 4" // "+" = "and" other voice "plus" (ok), "-" = mute, "×" = mute, other voice "X" (letter)
//Option 2
TextLabel.text = "1 ➕ 2 ➖ 3 ✖️ 4" // "+" = plus symbol, "-" = minus symbol, "×" = multiplication symbol
}
我希望使用 AVSpeechSynthesisVoice 在不同的语言中正确地语音符号 +(加号)、-(减号)、×(次),但选项 1 不正确或使某些符号静音......并且选项 2 更好但是再现“符号”一词
【问题讨论】:
标签: swift speech-recognition avspeechsynthesizer