【问题标题】:Swift - Reset/Restart SpeechSynthesizer after it finishesSwift - 完成后重置/重新启动 SpeechSynthesizer
【发布时间】:2017-07-19 09:54:20
【问题描述】:

我正在编写一个应用程序来向学生阅读随机学习问题。

基本流程是:

  • 生成随机问题
  • 将文本分配给 SpeechUtterrance
  • 使用 SpeechSynthesizer 播放 SpeechUtterance
  • 得到学生的答案
  • 检查一下
  • 生成一个新的随机问题
  • 重复

一切正常,除了我无法阅读多个问题。它会说第一个,接受一个答案,但我无法让它阅读后续的话语。

在运行 didFinish 后,我是否可以调用一种方法来重置 SpeechSynthesizer/SpeechUtterance?

【问题讨论】:

  • 所以我提到我在抢学生的答案。我正在使用 SFSpeechRecognizer 来执行此操作。经过一些测试,如果我不使用语音识别器读取后续的话语,没问题。我的猜测是我缺少 AVSpeechSynthesizer 和 SFSpeechRecognizer 之间的一些交互,如果这有助于任何人缩小范围?

标签: swift avspeechsynthesizer avspeechutterance


【解决方案1】:

所以我使用 SFSpeechRecognizer 和 AVSpeechSynthesizer 并启动录音机切断音频通道来播放音频。

我不得不改变

try audioSession.setCategory(AVAudioSessionCategoryRecord)

try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)

这解决了我的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-15
    • 1970-01-01
    • 2014-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-01
    • 1970-01-01
    相关资源
    最近更新 更多