我正在尝试将下面的curl命令转换为python
curl -X POST -u "apikey:my_key" --header "Content-Type:" --data-binary @testaudio1.wav "https://gateway-lon.watsonplatform.net/speech-to-text/api/v1/recognize?speaker_labels=true"
curl命令是一个有效的命令,但我无法获得与python相对应的命令。
我尝试了下面的代码
import json, sys
from os.path import join, dirname
from watson_developer_cloud import SpeechToTextV1
wav_file = sys.argv[1]
speech_to_text = SpeechToTextV1(
iam_apikey='my_api',
url='https://gateway-lon.watsonplatform.net/speech-to-text/api/v1'
)
with open(wav_file, 'rb') as audio:
result = speech_to_text.recognize(audio, content_type='audio/wav', timestamps=True,
word_confidence=True, speaker_labels=True)但是它似乎抛出了一个错误AppData\Local\Continuum\Anaconda3\lib\socket.py", line 732, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed
发布于 2018-12-14 16:23:26
使用requests模块。
Ex:
import requests
with open(wav_file, 'rb') as audio:
response = requests.post("https://gateway-lon.watsonplatform.net/speech-to-text/api/v1/recognize?speaker_labels=true",
headers={'apikey': 'my_key'},
data=audio))https://stackoverflow.com/questions/53775730
复制相似问题