nimbleape / asterisk-dialogflow-rtp-audioserver

MIT License
38 stars 18 forks source link

concurrent audio and distortion #37

Open 0x1stvan opened 1 month ago

0x1stvan commented 1 month ago

When integrating Dialogflow with Asterisk for voice interactions, there an issue where audio playback becomes distorted. This occurs specifically when a new transcript is added while the previous Dialogflow audio is still playing. The old audio continues to play concurrently with the new audio, resulting in an overlap that causes distortion.

danjenkins commented 1 month ago

Hey @0x1stvan - Is this something you can make a pull request for? Need to clear the buffer when receiving new audio from dialogflow to clear down the previous unplayed audio - this isn't something we're working on currently unless someone wants to pay for consultancy on it.

0x1stvan commented 1 month ago

Hey @0x1stvan - Is this something you can make a pull request for? Need to clear the buffer when receiving new audio from dialogflow to clear down the previous unplayed audio - this isn't something we're working on currently unless someone wants to pay for consultancy on it.

Hi @danjenkins , thanks for the quick reply. Tried to fix it, but i'm not really familiar with nodejs, if you can add me a hint how to do it i can create a pull request if working.

Can you please take a quick look to this issue also? https://github.com/nimbleape/asterisk-dialogflow-rtp-audioserver/issues/20

It looks like this bug still there, setting singleutterance to true causes crash

danjenkins commented 1 month ago

Yeah I need to look into the single utterance thing but ultimately I haven't looked at this app in a while.

On how to clear down the audio....

https://github.com/nimbleape/asterisk-dialogflow-rtp-audioserver/blob/master/lib/DialogFlowConnector.js#L178

Thats holding all of the previous timeouts but its a local variable to that function... so make it attached to the class so that you can then call

this.timeouts.forEach((ref) => {
                        clearTimeout(ref);
                    });

On line 178. instead of making an empty array you'll be clearing down the set of timeout refs

0x1stvan commented 1 month ago

Thanks @danjenkins , added PR https://github.com/nimbleape/asterisk-dialogflow-rtp-audioserver/pull/39, can you check it?