#๐Ÿ”’ Phone call website failing to load individual audio blobs

4 messages ยท Page 1 of 1 (latest)

molten tangleBOT
#

@fair salmon

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

fair salmon
#

Im working on a flask/ quart app that records your voice on one page, stores it in json and on the other page it loads the json and sends it to the page to load it in. Im doing this with websockets to make it more like a phone call. So every (timeframe) it sends the data to the page and load it to instantly play it like a phone call.

Here are some code snippets of what I have:

The endpoints:

@app.websocket('/listen')
async def call_socket():
    await websocket.accept()
    print("ws")
    try:
        datalist = json.load(open("queue.json"))
        for i in range(len(datalist)):
            data = base64.b64decode(datalist[str(i)].encode())
            await websocket.send(data)
            datalist.pop(str(i))
            with open("queue.json", "w") as f:
                json.dump(datalist, f, indent=4)
            time.sleep(1)

@app.websocket('/call')
async def websocket_endpoint():
    await websocket.accept()
    try:
        index = 0
        while True:
            data = await websocket.receive()
            datalist = json.load(open("queue.json"))
            print(str(datalist) + "aa")
            datalist[str(index)] = base64.b64encode(data).decode()
            index += 1
            with open("queue.json", "w") as f:
                json.dump(datalist, f, indent=4)
#

This part works and has been tested, the problem is at the receiving of data:

I first tried loading all the audioblobs and putting them together like this (it worked)

        socket.onmessage = (message) => {
            audioChunks.push(message.data);
            const audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
            audioElement.src = blobUrl;
            
        };

But when I tried to load the individual parts to instantly play them.

        socket.onmessage = (message) => {
            blob = message.data.slice(0, message.data.size, "audio/webm;")

            const blobUrl = URL.createObjectURL(blob);

            audioElement.onerror = function() {
                console.error('Failed to load audio:', audio.error);
            };
            audioElement.src = blobUrl;
            audioElement.play();
        };

I kept getting an error:

listen:41 Failed to load audio: MediaErrorย {code: 4, message: 'DEMUXER_ERROR_COULD_NOT_OPEN: FFmpegDemuxer: open context failed'}
audioElement.onerror @ listen:41
error (asynchroon)
socket.onmessage @ listen:40
listen:1 Uncaught (in promise) DOMException: Failed to load because no supported source was found.

I dont know what to do with this error and was hoping someone could find an oversight.

molten tangleBOT
#

@fair salmon

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.