【问题标题】:Adafruit I2S mems microphone not working with Contune Speech recognition. (Google cloud speech api)Adafruit I2S mems 麦克风不适用于 Contune 语音识别。 (谷歌云语音api)
【发布时间】:2018-07-06 01:40:23
【问题描述】:

我将这个库与带有 Raspbian 和 Adafruit I2S mems 麦克风的 Raspberry pi 3 一起使用。我可以在树莓派上使用 i2s 麦克风,它在正常录音时工作得很好,但是在使用 Speech_Recognition 和 Google Speech Cloud API 时它不起作用,我做了一些诡计,它与 microphone_recognition.py 完美配合.

我使用的技巧是在

microphone_recognition.py

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

speech_recognition/__init__.py

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

它完美地输出了

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

但是在尝试 background_listening.py

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) 

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

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

调试后的问题补充

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

一些调试 -

                print(format(energy)) 
        print(format(self.energy_threshold))
                if energy > self.energy_threshold:
        print("inside energy") 
        print(format(energy)) 
            print(format(self.energy_threshold)) 
        break

                # dynamically adjust the energy threshold using asymmetric weighted average
                if self.dynamic_energy_threshold:
        print(" inside dynamic_energy_threshold")
                    damping = self.dynamic_energy_adjustment_damping ** seconds_per_buffer 
                    target_energy = energy * self.dynamic_energy_ratio
                    self.energy_threshold = self.energy_threshold * damping + target_energy * (1 - damping)
        print(format(self.energy_threshold))
        print("end dynamic_energy_threshold") 

102982050 117976102.818 - 开始且始终处于高位,因此永远不会打破这个循环,即使在说话之后,在 dynamic_energy_threshold 内 119548935.608 end dynamic_energy_threshold inside listen -6.1.1 97861662 119548935.608 里面 dynamic_energy_threshold 120722993.56 end dynamic_energy_threshold 里面听 -6.1.1 84062664 120722993.56

在这里,我尝试使能量和三态能量相等并打破循环。

            print(format(energy)) 
    print(format(self.energy_threshold))
    **self.energy_threshold = float(energy)**
            if energy >= self.energy_threshold:
    **print("inside energy")** 
    print(format(energy)) 
        print(format(self.energy_threshold)) 
    break

输出

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

【问题讨论】:

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


    【解决方案1】:

    所以我做了一个解决方法, 解决方案 - speech_recognition/__init__.py - 库

    Microphone.__init__() - 方法

    self.format = self.pyaudio_module.paInt32
    

    识别器/adjust_for_ambient_noise - 方法

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

    而且它工作得非常完美,但现在我必须找到一种方法来停止 Google 语音 api 发送请求(如果没有语音)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-15
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多