简体   繁体   English

Python“语音识别”在 Mac m1 上不起作用

[英]Python “SpeechRecognition” not working on Mac m1

Ok.好的。 so after the troubling installation of PyAudio,所以在麻烦安装 PyAudio 之后, PyAudio 仍然无法正常工作

PyAudio still isn't found! PyAudio 仍然没有找到! I did pip3 list just to show it's installed我做了 pip3 list 只是为了显示它已安装pip3 说它已安装

What could the issue possibly be?问题可能是什么?

I am on Mac m1, I tried installing portaudio, I tried reinstalling pyaudio and speech_recognition This is also my code:我在 Mac m1 上,我尝试安装 portaudio,我尝试重新安装 pyaudio 和 speech_recognition 这也是我的代码:

import speech_recognition as sr
#obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)
    print(r.recognize_google(audio))

Please help.请帮忙。

First, install homebrew on your Mac.首先,在你的 Mac 上安装自制软件。

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Copy this code and paste it in your terminal to download and install homebrew and then install PyAudio with homebrew.复制此代码并将其粘贴到您的终端以下载并安装 homebrew,然后使用 homebrew 安装 PyAudio。

brew install portaudio
sudo brew link portaudio
pip install pyaudio

Run these commands in the terminal and I guess now PyAudio will work.在终端中运行这些命令,我猜现在 PyAudio 可以工作了。

I had to spend at least 3 days of my project trying to install PyAudio.我必须花费至少 3 天的时间来尝试安装 PyAudio。 This method worked for me.这种方法对我有用。

On M1 you need to use the latest portaudio, see this issue's response .在 M1 上您需要使用最新的 portaudio, 请参阅此问题的回复

brew uninstall portaudio
brew install portaudio --HEAD
cd $(brew --prefix portaudio)

# Links the headers to /usr/local/include
for f in $PWD/include/*.h; do ln -s $f /usr/local/include/${f##*/}; echo ${f##*/}; done

# Links the static libs to /usr/local/lib
for f in $PWD/lib/*.a; do ln -s $f /usr/local/lib/${f##*/}; echo ${f##*/}; done

# Links the dynamic libs to /usr/local/lib
for f in $PWD/lib/*.dylib; do ln -s $f /usr/local/lib/${f##*/}; echo ${f##*/}; done

pip3 install pyaudio

And then that just installs correctly!然后就可以正确安装了!

Tested with PyAudio 0.2.11, portaudio ( eec7bb7 ), on macOs 11.2.3 with M1 processor.在带有 M1 处理器的 macOS 11.2.3 上使用 PyAudio 0.2.11、portaudio ( eec7bb7 ) 进行了测试。

This approach can be reused to link any library you install with Homebrew btw.顺便说一句,这种方法可以用于链接您安装的任何库与 Homebrew。 It's a common issues with ffmpeg, openssl, and many other libs.这是 ffmpeg、openssl 和许多其他库的常见问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM