How to embed Google Speech to Text API in Python program?

被刻印的时光 ゝ 提交于 2020-01-02 01:57:05

问题


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.



来源:https://stackoverflow.com/questions/19828332/how-to-embed-google-speech-to-text-api-in-python-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!