How to embed Google Speech to Text API in Python p

2020-08-26 11:18发布

问题:

I have a project in which I have created a chat program between a client and host, and I have to embed Speech to Text in it. Is there any way by which I can embed Google Speech to Text API in my program ??

回答1:

This is probably what you do not want to use in your case, but for other's who may need this for a one-off project, I hacked together a simple python client a while ago that uses the APIs built into Chrome for voice search:

https://github.com/korylprince/python-google-transcribe

For it to work, you must have 16000Hz encoded FLACs, and they have to be fairly short.

Also, like the comments mention, the API is unofficial, so who knows when it will stop working.



回答2:

There is a package in PyPI called Speech Recognition which looks like it will do this. The live (i.e. via microphone) API looks fantastically simple.

# NOTE: this requires PyAudio because it uses the Microphone class
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:                # use the default microphone as the audio source
    audio = r.listen(source)                   # listen for the first phrase and extract it into audio data

try:
    print("You said " + r.recognize(audio))    # recognize speech using Google Speech Recognition
except LookupError:                            # speech is unintelligible
    print("Could not understand audio")

It also has capabilities for transcribing WAV files, running as a background process, providing confidence values for the transcription, etc.



回答3:

You can try Nexiwave's free speech-to-text api. Here is the python sample: http://nexiwave.com/api_samples/nexiwave_py.txt. Also check the API guide: http://nexiwave.com/index.php/119-integrate-in-5-minutes . Pretty straightforward.

You'd have to register first to use the free plan.