如何从谷歌麦克风搜索输出到python脚本?

时间:2017-01-20 20:43:26

标签: python search microphone box

我目前正在使用谷歌将语音转录为文字。但它太慢了。我想使用谷歌麦克风搜索框输出(因为它几乎是实时)。我一直在阅读Selenium示例,但找不到任何返回语音搜索文本的内容。

我现有的代码:

import time, wave, pymedia.audio.sound as sound
import pyautogui
import pyaudio,os
import speech_recognition as sr


f1= wave.open( 'HelloWorld.wav', 'rb' )
sampleRate1= f1.getframerate()
channels1= f1.getnchannels()
format= sound.AFMT_S16_LE
snd1= sound.Output( sampleRate1, channels1, format )
s1= f1.readframes( 800000 )


def hello():
    snd1.play( s1 )


def mainfunction(source):
    audio = r.listen(source)
    user = (r.recognize_google(audio, language = "en-us", show_all=False))
    print(user)
    if user == "hello world":
        residential()

    else:
        pass    

try:
    if __name__ == "__main__":
        r = sr.Recognizer()
        with sr.Microphone() as source:
            while 1:
                r.pause_threshold = 0.5
                r.energy_threshold = 150
                r.adjust_for_ambient_noise(source, duration = 0.5)
                mainfunction(source)

0 个答案:

没有答案