Skip to content

Improve /transcribe endpoint compatibility and robustness #11

@Forchapeatl

Description

@Forchapeatl

Problem

Currently, the /transcribe endpoint uses request.stream.read(),

chunk = request.stream.read(2048000)

it assumes a continuous stream of data. This makes it difficult to interface with standard JSON-based clients

const data = { chunk_id: chunkId, audio_b64: base64data };
// construct the URL from the host and port
const serverhost = document.getElementById('serverhost').value;
const serverport = document.getElementById('serverport').value;
const transcribeurl = `http://${serverhost}:${serverport}/transcribe`;
const csrftoken = getCookie('csrftoken');
fetch(transcribeurl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
})
.then(response => {
if (response.ok) {
console.log(`Sent chunk ${chunkId} with ${buffer.length} samples`);

and can lead to JSONDecodeError if the stream chunks don't align perfectly with JSON boundaries.

Solution

Update the endpoint to handle standard application/json POST requests using Flask’s get_json(). This ensures immediate response to the client while the background thread processes the queue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions