pythoncurlpython-requestsmozilla-deepspeech

Convert cURL command to python using requests


I am using deepspeech and deespeech-server. I am able to send the cURL command:

curl -X POST --data-binary @what_time_is_it.wav http://localhost:8080/stt

This gives me the correct speech to text translation "what time is it".

I am now trying to achieve the same result with a python script. My code is:

import requests

data = {'data-binary': '@what_time_is_it.wav'}
response = requests.post("http://localhost:8080/stt", data=data)
print(response.content)
print(response.text)

I get the following output:

b'Speech to text error'

And on my server I get:

STT error: File format b'data'... not understood.

Does anyone have ideas for how I might fix this?


Solution

  • Try something like this:

    import requests
    
    filepath = '/path/to/what_time_is_it.wav'
    r = requests.post("http://localhost:8080/stt", data=open(filepath).read())
    print(r.status_code)
    print(r.content)
    print(r.text)