我想将固定句子的每个单词与录制的录音中的每个单词进行比较。
我现在有以下代码:
func compareWordwithVoice() {
let StringToLearn = wordToLearn
let StringToLearnArr = StringToLearn.components(separatedBy: " ")
let StringRecordedArr = transcriptionTextField.text.components(separatedBy: " ")
let wordCount = StringToLearnArr.count
word?.text = ""
for count in 0...Int(wordCount)-1{
if StringRecordedArr.indices.contains(count) {
if (StringToLearnArr[count] == StringRecordedArr[count]){
word.textColor = UIColor.green
word?.text = word.text! + " " + (StringToLearnArr[count])
} else {
word.textColor = UIColor.red
word?.text = word.text! + " " + (StringToLearnArr[count])
}
} else {
word.textColor = UIColor.black
word?.text = word.text! + " " + (StringToLearnArr[count])
}
}
wordToLearn表示与使用transcriptionTextField.text显示的句子进行比较的句子。
结果显示为word.text:
我想找一个用他的匹配颜色显示每个单词的算法,例如我必须重复句子“Hello my name is Robert”并且我记录“Hello my friend is Robert”,我想显示“你好”我的名字(红色的名字)是罗伯特“如果我记录”你好我的名字是罗伯特“,我想显示”你好我的名字是罗伯特(所有的话都是绿色的)“。