com.microsoft.cognitiveservices.speech.SpeechSynthesizer 失败并显示“USP 错误:等待第一个音频块超时”

发布于 2025-01-17 15:25:57 字数 1709 浏览 0 评论 0原文

因此,我正在尝试使用官方docs

= script%2cBrowserjs%2cwindowsInstall& pivots = programming- language

class TextToSpeech(val context: Context) {
  private val speechConfig: SpeechConfig = SpeechConfig.fromSubscription(SPEECH_SUBSCRIPTION_KEY, "southeastasia")
  private var speechSynthesizer: SpeechSynthesizer

  init {
    speechConfig.speechSynthesisLanguage = "fa-IR"
    speechConfig.speechSynthesisVoiceName = "fa-IR-DilaraNeural"
    speechConfig.enableAudioLogging()
    val audioConfig = AudioConfig.fromDefaultSpeakerOutput()
    speechSynthesizer = SpeechSynthesizer(speechConfig, audioConfig)
   }


  fun speak(pText: String) {

    speechSynthesizer.SynthesisStarted.addEventListener { _, _ ->
      Log.d(TAG, "speak: SynthesisStarted")
    }
    speechSynthesizer.SynthesisCompleted.addEventListener { _, _ ->
      Log.d(TAG, "speak: SynthesisCompleted")
    }
    speechSynthesizer.SynthesisCanceled.addEventListener { any: Any, speechSynthesisEventArgs: SpeechSynthesisEventArgs ->
      val details = SpeechSynthesisCancellationDetails.fromResult(speechSynthesisEventArgs.result)
      Log.d(TAG, "speak: SynthesisCanceled")
    }
    speechSynthesizer.Synthesizing.addEventListener { _, _ ->
      Log.d(TAG, "speak: Synthesizing")
    }
    speechSynthesizer.SpeakText(text)

  }

}

> “综合启动”将触发,然后几秒钟后,“综合验证”触发了以下结果

comcellationReason:错误 错误代码:ServicEtimeOut errordetails:USP错误:超时等待第一个音频块

so im trying to implement microsoft tts on android using Official Docs

my code looks like :

class TextToSpeech(val context: Context) {
  private val speechConfig: SpeechConfig = SpeechConfig.fromSubscription(SPEECH_SUBSCRIPTION_KEY, "southeastasia")
  private var speechSynthesizer: SpeechSynthesizer

  init {
    speechConfig.speechSynthesisLanguage = "fa-IR"
    speechConfig.speechSynthesisVoiceName = "fa-IR-DilaraNeural"
    speechConfig.enableAudioLogging()
    val audioConfig = AudioConfig.fromDefaultSpeakerOutput()
    speechSynthesizer = SpeechSynthesizer(speechConfig, audioConfig)
   }


  fun speak(pText: String) {

    speechSynthesizer.SynthesisStarted.addEventListener { _, _ ->
      Log.d(TAG, "speak: SynthesisStarted")
    }
    speechSynthesizer.SynthesisCompleted.addEventListener { _, _ ->
      Log.d(TAG, "speak: SynthesisCompleted")
    }
    speechSynthesizer.SynthesisCanceled.addEventListener { any: Any, speechSynthesisEventArgs: SpeechSynthesisEventArgs ->
      val details = SpeechSynthesisCancellationDetails.fromResult(speechSynthesisEventArgs.result)
      Log.d(TAG, "speak: SynthesisCanceled")
    }
    speechSynthesizer.Synthesizing.addEventListener { _, _ ->
      Log.d(TAG, "speak: Synthesizing")
    }
    speechSynthesizer.SpeakText(text)

  }

}

The Problem is when i call speak method the "SynthesisStarted" will trigger and then after a few seconds the "SynthesisCanceled" going triggered with following result

CancellationReason:Error
ErrorCode: ServiceTimeout
ErrorDetails:USP error: timeout waiting for the first audio chunk

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林迷了鹿 2025-01-24 15:25:58

存在网络套接字连接问题。首先需要检查即使没有识别输入,您想让连接保持多长时间。

对于访问令牌,应将访问令牌作为 Authorization: Bearer 标头发送到服务。每个访问令牌的有效期为 10 分钟。您可以随时获取新令牌,但是,为了最大限度地减少网络流量和延迟,我们建议在九分钟内使用相同的令牌。

以下是短音频场景的示例。

 POST /cognitiveservices/v1 HTTP/1.1
 Authorization: Bearer YOUR_ACCESS_TOKEN
 Host: westus.stt.speech.microsoft.com
 Content-type: application/ssml+xml
 Content-Length: 199
 Connection: Keep-Alive
    
 // Message body here...

There is a web socket connection problem. First need to check with how long you want to make the connection alive even there is no recognition of input.

For access token, the access token should be sent to the service as the Authorization: Bearer header. Each access token is valid for 10 minutes. You can get a new token at any time, however, to minimize network traffic and latency, we recommend using the same token for nine minutes.

The below is the example of short audio scenario.

 POST /cognitiveservices/v1 HTTP/1.1
 Authorization: Bearer YOUR_ACCESS_TOKEN
 Host: westus.stt.speech.microsoft.com
 Content-type: application/ssml+xml
 Content-Length: 199
 Connection: Keep-Alive
    
 // Message body here...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文