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

如何从谷歌麦克风搜索获取python脚本的输出?,python,search,microphone,box,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' )

我目前正在使用谷歌将语音转录成文本。但是它太慢了。我想改用谷歌麦克风搜索框输出(因为它几乎是实时的)。我一直在阅读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)