1

I'm trying to convert this curl command from the Kaldi docs:

curl -v -T test/data/english_test.raw -H "Content-Type: audio/x-raw-int; rate=16000" --header "Transfer-Encoding: chunked" --limit-rate 32000  "http://localhost:8888/client/dynamic/recognize"

To JS code, specifically fetch. I'm able to POST a binary file using fetch pretty easily but specifically what I need to do is use chunked transfer encoding. To the life of me I can't find any docs on this, and as far as I know in JS, it's really up to the user agent to set the transfer encoding. Would appreciate any pointers!

cuuupid
  • 912
  • 5
  • 20
  • 2
    I don't think `Fetch` gives you this level of control. – Barmar May 22 '19 at 20:27
  • See https://stackoverflow.com/a/49211413/441757 – sideshowbarker May 22 '19 at 22:52
  • @sideshowbarker so there's a lot on _consuming_ the data but I'm not worried about the response (the response only comes in the last chunk to begin with so it suffices to treat it as a normal response), specifically I need to send the request body in chunks – cuuupid May 23 '19 at 01:04
  • 1
    Ah OK then maybe see https://stackoverflow.com/questions/40939857/fetch-with-readablestream-as-request-body and https://github.com/whatwg/fetch/pull/425. So the Fetch spec provides a way to do this (create a request from a Request made from a ReadableStream), but unfortunately, I don’t think any browsers have shipped it yet. – sideshowbarker May 23 '19 at 02:45

1 Answers1

0

this is your js fetch req :

fetch('http://localhost:8888/client/dynamic/recognize', {
  method: 'PUT',
  headers: {
    'Content-Type': 'audio/x-raw-int; rate=16000',
    'Transfer-Encoding': 'chunked'
  },
  body: File(['<data goes here>'], 'test/data/english_test.raw')
});