使用请求将 cURL 命令转换为 python
Convert cURL command to python using requests
我正在使用 deepspeech 和 deespeech-server。我能够发送 cURL 命令:
curl -X POST --data-binary @what_time_is_it.wav http://localhost:8080/stt
这为我提供了正确的语音到文本翻译 "what time is it"。
我现在正尝试使用 python 脚本实现相同的结果。我的代码是:
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)
我得到以下输出:
b'Speech to text error'
在我的服务器上我得到:
STT error: File format b'data'... not understood.
有人知道我该如何解决这个问题吗?
尝试这样的事情:
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)
我正在使用 deepspeech 和 deespeech-server。我能够发送 cURL 命令:
curl -X POST --data-binary @what_time_is_it.wav http://localhost:8080/stt
这为我提供了正确的语音到文本翻译 "what time is it"。
我现在正尝试使用 python 脚本实现相同的结果。我的代码是:
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)
我得到以下输出:
b'Speech to text error'
在我的服务器上我得到:
STT error: File format b'data'... not understood.
有人知道我该如何解决这个问题吗?
尝试这样的事情:
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)