如何从Google语音获取音频文件到文本API

时间:2020-05-06 11:52:36

标签: speech-recognition text-to-speech speech-to-text google-text-to-speech

我正在使用runEnvironment = '[' + "'7031'" + ']' 语音获取文本。我也想获取我说或浏览器记录的音频文件。我可以得到这个音频文件吗?谢谢。

1 个答案:

答案 0 :(得分:0)

我希望你在python中工作...

import speech_recognition as sr

# to record audio
r = sr.Recognizer()
mic = sr.Microphone()

# to record audio
with mic as source:
    audio = r.listen(source)
# to play audio
try: 
    text = r.recognize_google(audio) 
    print "you said: " + text 
except sr.UnknownValueError: 
    print("Google Speech Recognition could not understand audio")

您可以更改和改进语音识别器的许多参数。如果您想了解更多信息,请检查this

这是Js的代码...

var recognition = new webkitSpeechRecognition();
recognition.continuous = true;

var output = document.getElementById('output');
recognition.onresult = function(event) {
  output.textContent = event.results[0][0].transcript;
};