英文:
Third party voice Api integration with twilio
问题
我想使用第三方语音API与Twilio进行文本转语音。
我尝试了几种方法,但没有找到任何信息。如果有办法可以做到的话,请帮助我。我看了Twilio的文档,但没有找到相关内容。
英文:
I want to use third-party voice Api to Twilio for text-to-speech.
I tried several ways but could not find anything. if there's any way I can do it, please help me do it. I saw Twilio's documentation but could not find anything relevant.
答案1
得分: 1
第三方 API 需要将文本转换并返回一个音频文件,例如 MP3 或 Wav。然后,您可以使用 Twilio Play 动词来播放音频文件:
var response = new VoiceResponse();
response.Play(new Uri("https://third-party-api.com/customaudio.mp3"));
上述的 C# 代码将生成以下 TwiML:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Play>https://third-party-api.com/customaudio.mp3</Play>
</Response>
上面示例中的 Uri 是第三方 API 生成的音频文件链接。Twilio 将播放这个音频文件给呼叫者。
如果您正在尝试实时进行此操作(而不是生成音频文件、存储它,然后稍后播放),第三方 API 必须迅速返回音频(少于 12 秒),否则 Twilio 将超时并结束通话。
我在实时 IVR 中使用了类似的方法,使用 Microsoft Azure Cognitive Services 进行文本到语音转换。12 秒是 Twilio 的限制,但理想情况下,第三方 API 应该更快地返回音频,以防呼叫者因为以为断开连接而挂断电话。
英文:
The third-party api needs to convert the text and return an audio file such as an MP3 or Wav. Then you use the Twilio Play verb to play the audio file:
var response = new VoiceResponse();
response.Play(new Uri("https://third-party-api.com/customaudio.mp3"));
The above c# code will produce this Twiml:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Play>https://third-party-api.com/customaudio.mp3</Play>
</Response>
The Uri in the above example is the link to the audio file produced by the third-party API. Twilio will play this audio file to the caller.
If you are trying to do this in real-time (vs. generating an audio file, storing it, and playing back later), the third-party api must return the audio promptly (less than 12 seconds) or Twilio will timeout and end the call.
I am using a similar approach with Microsoft Azure Cognitive Services for text-to-speech in a real-time IVR. 12 seconds is a Twilio limit but ideally the audio will be returned by the third-party API much quicker so the caller doesn't hang-up because they think they are disconnected.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论