简体   繁体   中英

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?

Maybe in the fashion that Python's SpeechRecognition library works?

For Bing translation, set BING_KEY=**your key** .

You could then do translation as bing_en_US=recognizer.recognize_bing(audio, key=BING_KEY, language="en-US") .

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

Get your key here: https://azure.microsoft.com/en-us/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:

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())

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