Open devsalman247 opened 3 weeks ago
Hi @devsalman247,
Thank you for your message. Is it possible that you forgot to create the .env
file in the frontend copying the provided env.example
? This file should include the NEXT_PUBLIC_WEBSOCKET_URL
environment variable that specifies the WebSocket url to connect to the backend, which by default should be "ws://localhost:8000/listen" if you are running it locally.
I updated it anyway in the code and set that url as a default, so it's no longer necessary to set the env variable if you are running it locally.
Please let me know if this doesn't solve it or you find any other issues
Hi @devsalman247,
Thank you for your message. Is it possible that you forgot to create the
.env
file in the frontend copying the providedenv.example
? This file should include theNEXT_PUBLIC_WEBSOCKET_URL
environment variable that specifies the WebSocket url to connect to the backend, which by default should be "ws://localhost:8000/listen" if you are running it locally.I updated it anyway in the code and set that url as a default, so it's no longer necessary to set the env variable if you are running it locally.
Please let me know if this doesn't solve it or you find any other issues
Yes, I have created .env on frontend & it is connecting..
Moreover, I receive audio bytes on backend but do not receive any response from Deepgram... But when I specify sample_rate & encoding scheme Deepgram returns empty string.
That's strange. The frontend uses the MediaRecorder Web API to stream the microphone audio and Deepgram should automatically detect the format and encoding. You shouldn't specify it in the connection options. You can learn more here.
Can you check the format/encoding of the microphone stream in the frontend? Maybe it's not supported by Deepgram.
Add this at the end of the startMicrophone
function to check it:
mediaRecorderRef.current.addEventListener('start', () => {
console.log(mediaRecorderRef.current.mimeType);
});
You can also try to set a specific MIME type when creating the MediaRecorder instance and see if it works:
mediaRecorderRef.current = new MediaRecorder(stream, { mimeType: 'audio/webm;codecs=opus' });
This is the format/encoding that my browser is using, and it works well with Deepgram.
I've changed the mimetype as you told in previous reply but still no response from deepgram:
async function startMicrophone() {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
mediaRecorderRef.current = new MediaRecorder(stream, {
mimeType: "audio/webm;codecs=opus",
});
console.log(mediaRecorderRef.current.mimeType);
mediaRecorderRef.current.addEventListener("dataavailable", (e) => {
if (e.data.size > 0 && wsRef.current.readyState == WebSocket.OPEN) {
wsRef.current.send(e.data);
}
});
mediaRecorderRef.current.start(250);
}
And the Deepgram config options are as they were initially, without specifying the encoding/channels/sample rate?
And the Deepgram config options are as they were initially, without specifying the encoding/channels/sample rate?
Yes
Try this at the end of the transcribe_audio
method in the Assistant
class:
try:
audio_file = open('audio.webm', 'wb')
while not self.finish_event.is_set():
# Receive audio stream from the client and send it to Deepgram to transcribe it
data = await self.websocket.receive_bytes()
audio_file.write(data)
await dg_connection.send(data)
audio_file.close()
finally:
await dg_connection.finish()
Then start the app, talk to the microphone for a bit and listen to the saved audio file in the backend. This way you can see if it's receiving the audio correctly. If it is, then the issue is probably with the Deepgram connection.
I am not receiving any result from deepgram when running app... I had tested local python script first which is still working perfectly fine but when audio is streamed through frontend using websocket I do not receive any output in console:
When I tried to change deepgram config by adding sample_rate & encoding params I receive output from deepgram but the result is empty string:
OS: Windows 11 IDE: VS Code Poetry Version: Poetry (version 1.8.3) Poetry config:
NOTE: I've not made any changes to frontend & backend except changing mentioned deepgram config.