简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM