Skip to content

Instantly share code, notes, and snippets.

@vinitpayal
Last active August 19, 2024 16:03
Show Gist options
  • Save vinitpayal/ba933ec0b5e1ffa4b472cb34ef7b2ae0 to your computer and use it in GitHub Desktop.
Save vinitpayal/ba933ec0b5e1ffa4b472cb34ef7b2ae0 to your computer and use it in GitHub Desktop.
stream test with javascript
const endpoint = "http://127.0.0.1:5015/getConversation"
const fd = JSON.stringify({
"sourceLang1AudioPath": "../data/input/mandarin.wav",
"sourceLanguage": "mt",
"destinationLanguage2": "hi",
"destinationLanguage3": "en",
"sourceLang1TextPath": "/tmp/asr_demo_2.txt",
"destinationLang2TextPath": "/tmp/mt_demo_2.txt",
"destinationLang3TextPath": "",
"destinationLang3AudioPath": "/tmp/tts_demo_2.wav",
"outputAudioRequired": true
})
const requestOptions = {
method: "POST",
body: fd,
redirect: "follow"
};
fetch(endpoint, requestOptions)
.then(response => {
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
function read() {
console.log(`-| Reading `);
reader.read().then(({ done, value }) => {
console.log(`is done?: ${done}`)
if (done) {
console.log('stream completed')
return;
}
console.log('reading next chunk ...')
console.log(done, value)
read()
})
}
read()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment