Google语音API抛出EOF错误,而不是执行音频转录。

huangapple go评论76阅读模式
英文:

Google-speech-api throws EOF error instead of performing audio transcription

问题

在我的项目中,我正在使用Golang开发一个WebSocket服务器,通过ARI控制Asterisk通道,并在同一通道上执行实时音频转录,使用Google语音API。在连接时,我希望将Asterisk通道的音频保存到文件中,同时将音频发送到Google并获取转录结果。音频是通过Asterisk的audiofork应用程序发送的,这样我就可以在音频在另一个线程上流式传输时使用ARI操作通道。

问题是,当我将帧发送到Google时,我在服务器上发送的第一帧和每个连续的帧都会收到EOF错误。但是,当我使用sox将保存的帧的二进制文件转换为wav文件时,我可以听到通道上的音频录音,所以由audiofork发送的帧并没有损坏。有人可以给我一些建议,如何使Google语音API与我合作吗?

英文:

In my project I am developing a websocket server in golang which is controlling asterisk channel via ARI and performing live audio transcription on the same channel with google-speech-api. On connection I want to save audio from an asterisk channel to file while simultanously sending audio to google and get a transcript. Audio is being sent by asterisk audiofork app so that I can manipulate channel with ARI while audio is streamed on another thread.

The problem is that when I send frames to google I get EOF error on the first and every consecutive frame I send from my server but when I convert binary file with saved frames to wav using sox I get recording of audio on the channel so the frames send by audiofork aren't corrupted. Can anyone give me any advice how to make google-speech-api cooperate with me?

答案1

得分: 0

这很尴尬,但这只是我犯的一个愚蠢错误,因为在创建谷歌客户端的函数中,我在延迟关闭客户端时放错了位置。所以当函数返回语音客户端变量时,它被同一个函数自动关闭了。修复后,一切都按预期工作了。

英文:

This is pretty embarrasing but this was just dumb mistake on my side because in my function creating google client I put closing client on defer so when my function retuned speech client variable it was automatically closed by the same function so after fixing that everything works as intented.

huangapple
  • 本文由 发表于 2021年10月7日 15:28:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/69477052.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定