简体   繁体   English

在Python中调用Bing或IBM文本语音API?

[英]Calling Bing or IBM text-to-speech API in Python?

Is there a way to call the Bing Text To Speech API or the IBM Text To Speech API through Python? 有没有一种方法可以通过Python调用Bing Text To Speech API或IBM Text To Speech API?

Maybe in the fashion that Python's SpeechRecognition library works? 也许采用Python的SpeechRecognition库起作用的方式?

For Bing translation, set BING_KEY=**your key** . 对于Bing翻译,请设置BING_KEY=**your key**

You could then do translation as bing_en_US=recognizer.recognize_bing(audio, key=BING_KEY, language="en-US") . 然后,您可以按照bing_en_US=recognizer.recognize_bing(audio, key=BING_KEY, language="en-US")

Ref: https://pypi.python.org/pypi/SpeechRecognition/ 参考: https : //pypi.python.org/pypi/SpeechRecognition/

Get your key here: https://azure.microsoft.com/en-us/try/cognitive-services/?api=speech-api 在此处获取密钥: https : //azure.microsoft.com/zh-cn/try/cognitive-services/?api=speech-api

I believe you can add: 我相信您可以添加:

return recognizer.recognize_ibm(audio)

in the code after downloading everything you need including the IBM zip file here: 在下载所有所需内容(包括此处的IBM zip文件)之后的代码中:

https://github.com/watson-developer-cloud/speech-to-text-websockets-python https://github.com/watson-developer-cloud/speech-to-text-websockets-python

heres the entire code: 完整的代码如下:

import speech_recognition


while 1:
    recognizer = speech_recognition.Recognizer()

    def listen():

            with speech_recognition.Microphone() as source:
                    recognizer.adjust_for_ambient_noise(source)
                    audio = recognizer.listen(source)

            try:
                    # return recognizer.recognize_sphinx(audio) 
                    #return recognizer.recognize_google(audio)
                    return recognizer.recognize_ibm(audio)
            except speech_recognition.UnknownValueError:
                    print("Could not understand audio")
            except speech_recognition.RequestError as e:
                    print("Recog Error; {0}".format(e))

            return ""


    listen()

    print (listen())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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