Adafruit I2S Mems麦克风无法与Contune语音识别一起使用。 (Google云语音API)

时间:2018-06-21 15:44:56

标签: raspberry-pi speech-recognition pyaudio google-speech-api

我正在将此库与具有Raspbian和Adafruit I2S mems麦克风的Raspberry pi 3配合使用。我可以在树莓派上使用i2s麦克风,并且可以正常录制,但是在const auto it = search(cbegin(x), cend(x), cbegin(value), cend(value)); if(it != cend(x)) { x.replace(it, next(it, size(value)), crbegin(value), crend(value)); } 与Google Speech Cloud API一起使用时却无法正常工作,我做了一些Trickery,并且与{ {1}}。

我使用的技巧是

microphone_recognition.py

Speech_Recognition

speech_recognition / __ init __。py

microphone_recognition.py

它可以完美输出

  

ALSA lib pcm.c:2495:(snd_pcm_open_noupdate)未知的PCM bluealsa   对/ tmp / jack-1000 / default / jack_0的connect(2)调用失败(err =否   文件或目录)尝试连接服务器失败说点什么!   Google Cloud Speech认为您说你好

但是尝试 background_listening.py

r = sr.Recognizer()
with sr.Microphone(device_index = 2, sample_rate = 48000) as source:
    print("Say something!")
    audio = r.record(source, duration = 5)
  

ALSA lib pcm.c:2495:(snd_pcm_open_noupdate)未知的PCM bluealsa   对/ tmp / jack-1000 / default / jack_0的connect(2)调用失败(err =否   文件或目录)尝试连接服务器失败

我使用的是 speech_recognition / init 的相同设置。没有给出输出。

调试后问题的补充

我停留在下面给出的循环中,不要前进,也不要调用回调(识别器,音频)。我正在使用### init.py self.format = self.pyaudio_module.paInt32 < / strong>,并且belove代码也来自同一

一些调试-

self.device_index = device_index
            self.format = self.pyaudio_module.paInt32
  

102982050   117976102.818-从头开始并始终处于高电平,因此永不中断,即使在讲话后,也要在dynamic_energy_threshold内部   119548935.608内部的dynamic_energy_threshold结束-6.1.1 97861662   119548935.608内部dynamic_energy_threshold   120722993.56结束在里面的dynamic_energy_threshold监听-6.1.1 84062664   120722993.56

在这里,我尝试使能量等于三叉戟能量并打破循环。

import time

import speech_recognition as sr

# this is called from the background thread

def callback(recognizer, audio):

    GOOGLE_KEY= r"""{ MY KEY }"""

    # received audio data, now we'll recognize it using Google Speech Recognition
    try:
        print("Google Speech Recognition thinks you said " + recognizer.recognize_google_cloud(audio, credentials_json=GOOGLE_KEY))
    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition service; {0}".format(e))


r = sr.Recognizer() 
with sr.Microphone(device_index=2, sample_rate = 48000) as source:
    r.adjust_for_ambient_noise(source)  # we only need to calibrate once, before we start listening

# start listening in the background (note that we don't have to do this inside a `with` statement)
stop_listening = r.listen_in_background(source, callback)
# `stop_listening` is now a function that, when called, stops background listening

# do some unrelated computations for 5 seconds
for _ in range(50): time.sleep(0.1)  # we're still listening even though the main thread is doing other things

# calling this function requests that the background listener stop listening
stop_listening(wait_for_stop=False)

# do some more unrelated things
while True: time.sleep(0.1) 

输出

  

105836705   116487614.952 =这是能量阈值,始终很高。并继续循环内部能量    105836705   105836705.0

1 个答案:

答案 0 :(得分:0)

所以我做了个变通, 解决方案- speech_recognition / __ init__.py-库

麦克风。__init __()-方法

self.format = self.pyaudio_module.paInt32

识别器/ adjust_for_ambient_noise-方法

energy = audioop.rms(buffer, source.SAMPLE_WIDTH)/1000000 

它的运行确实非常完美,但是现在我必须找到一种方法,如果没有语音,则可以停止 发送请求 Google语音API。