首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Curl转换为Python | IBM STT

将Curl转换为Python | IBM STT
EN

Stack Overflow用户
提问于 2018-12-14 16:12:24
回答 1查看 64关注 0票数 0

我正在尝试将下面的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相对应的命令。

我尝试了下面的代码

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2018-12-14 16:23:26

使用requests模块。

Ex:

代码语言:javascript
复制
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))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53775730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档