How to play and record voice at same time in twilio

╄→гoц情女王★ 提交于 2019-12-25 09:30:14

问题


I was working with twilio

my case is when user make a call IVR will ask for user mood and then start recording for 10 second, take that recording to server find podcast according to user mood and send back TWIML with podcast mp3 url and play it to user

I'm done with this job

now i want to implement the feature in which when user user say "Skip" or "I don't like this one please skip"(or something similar which i will handle with Ai) immediately stop playing and goto server and get another podcast mp3 url and play it

for doing this i need to do something like this:

<?xml version="1.0" encoding="UTF-8" ?>  
<Response> 
    <Play>https://somechannel.com/podcast.mp3</Play>
    <record action='/voice/check-what-user-said'></record>
</Response>

but doing this will not solve my problem because twilio will start recording after finish playing, I want to record each 10 seconds and send it to server continuously when user is listening podcast

let say, twilio start playing mp3, it also start recording

e.g:
playing 
00:00 - start recording for ten seconds
00:10 - finish recording and send it to server
00:11 - start another recording for 10 seconds
00:20 - finish recording and send it to server

each time when we get recording on server, i will convert recording to text ad check if user said "skip", if yes i will modify call on the fly


回答1:


Twilio developer evangelist here.

I'm afraid that it is currently not possible* to record slices of a call while simultaneously playing an mp3.

Can I suggest that rather than voice you use a key press for this functionality instead? You can then use the following TwiML (as an example)

<?xml version="1.0" encoding="UTF-8" ?>  
<Response> 
  <Say>Press any digit to skip this podcast</Say>
  <Gather action="/voice/check-digits" numDigits="1">
    <Play>https://somechannel.com/podcast.mp3</Play>
  </Gather>
</Response>

Then you will need an endpoint in your application at /voice/check-digits that directs the user onto the next podcast.

*OK, it might be possible if you play the audio into a conference and have another script dial into the conference and record 10 seconds, then hangup as another script dials in to start recording. But even then, you'd be trying to extract the voice of the caller from the audio of the podcast and that is unlikely to be accurate at all. Especially if a voice in the podcast says "skip". So I still recommend using <Gather>!



来源:https://stackoverflow.com/questions/44075338/how-to-play-and-record-voice-at-same-time-in-twilio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!