Skip to content

Voice lagging with OpenAi Realtime #26

@3Omarito

Description

@3Omarito

Hello Dear,
I've an issue while integrate Asterisk with OpenAi using Realtime API. Shortly, I use Audiosocke to connect with Asterisk and then once the connection has begun, I start the OpenAi connection. When I use res.play function out of OpenAi connection function it works fine, but when I use it inside OpenAi connection the played file is lagging and you cannot recognize the voice.

`
audioSocket.onConnection(async (req, res) => {

openAiWs.on( 'message', async (data) => {
await res.play("/root/moh.wav");

        try {
            const response = JSON.parse(data);


            if (response.type === 'response.audio.delta' && response.delta) {
                /*const audioDelta = {
                    event: 'media',
                    streamSid: streamSid,
                    media: { payload: response.delta }
                };*/

                //console.log(typeof data); // Should output 'object' for Buffer
                //console.log(Buffer.isBuffer(data)); // Should output true if data is a Buffer

                //console.log('Firstone:', response);

                const finaldata = Buffer.from(response.delta, "base64");
                //console.log('Final Data is:', finaldata);

                //await res.write(finaldata);
                await res.play("/root/moh.wav");
            }
            } catch (error) {
            console.error('Error processing OpenAI message:', error, 'Raw message:', data);
                            }

});
});
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions