Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for m1 mac #40

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

enemaliwilliam
Copy link

I was able to get it to run on my m1 mac with a couple tweaks. Still needs to be optimized but it works

@AndrewBreyen
Copy link

@enemaliwilliam Is this ONLY for Apple Silicon macs? would love to get it working on Intel too!

Currently getting this on my Intel mac when running pip install -r requirements.txt:

Building wheels for collected packages: openai-whisper, pyaudio
  Building wheel for openai-whisper (pyproject.toml) ... done
  Created wheel for openai-whisper: filename=openai_whisper-20230314-py3-none-any.whl size=796901 sha256=e71ad9dbd48dbac475263b4e66ae50ebe22bfff9c46b948efa8b70a7809dcc1d
  Stored in directory: /Users/abreyen/Library/Caches/pip/wheels/b2/13/5f/fe8245f6dc59df505879da4b2129932e342f02a80e6b87f27d
  Building wheel for pyaudio (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for pyaudio (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [18 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-12.6-x86_64-cpython-310
      creating build/lib.macosx-12.6-x86_64-cpython-310/pyaudio
      copying src/pyaudio/__init__.py -> build/lib.macosx-12.6-x86_64-cpython-310/pyaudio
      running build_ext
      building 'pyaudio._portaudio' extension
      creating build/temp.macosx-12.6-x86_64-cpython-310
      creating build/temp.macosx-12.6-x86_64-cpython-310/src
      creating build/temp.macosx-12.6-x86_64-cpython-310/src/pyaudio
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/Users/abreyen/.pyenv/versions/3.10.8/include/python3.10 -c src/pyaudio/device_api.c -o build/temp.macosx-12.6-x86_64-cpython-310/src/pyaudio/device_api.o
      src/pyaudio/device_api.c:9:10: fatal error: 'portaudio.h' file not found
      #include "portaudio.h"
               ^~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyaudio
Successfully built openai-whisper
Failed to build pyaudio
ERROR: Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects

@zarifpour
Copy link
Contributor

@enemaliwilliam I am getting this error when I try to run on an M1 Max:

❯ python main.py
.../ecoute/ecoute_env/lib/python3.11/site-packages/whisper/timing.py:57: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.
  @numba.jit
[INFO] Adjusting for ambient noise from Default Mic. Please make some noise from the Default Mic...
[INFO] Completed ambient noise adjustment for Default Mic.
[INFO] Adjusting for ambient noise from Default Speaker. Please make or play some noise from the Default Speaker...
Traceback (most recent call last):
  File ".../ecoute/AudioRecorder.py", line 25, in adjust_for_noise
    self.recorder.adjust_for_ambient_noise(self.source)
  File ".../ecoute/custom_speech_recognition/__init__.py", line 402, in adjust_for_ambient_noise
    assert source.stream is not None, "Audio source must be entered before adjusting, see documentation for ``AudioSource``; are you using ``source`` outside of a ``with`` statement?"
           ^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Audio source must be entered before adjusting, see documentation for ``AudioSource``; are you using ``source`` outside of a ``with`` statement?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../ecoute/main.py", line 121, in <module>
    main()
  File ".../ecoute/main.py", line 78, in main
    speaker_audio_recorder = AudioRecorder.DefaultSpeakerRecorder()
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../ecoute/AudioRecorder.py", line 63, in __init__
    self.adjust_for_noise("Default Speaker", "Please make or play some noise from the Default Speaker...")
  File ".../ecoute/AudioRecorder.py", line 24, in adjust_for_noise
    with self.source:
  File ".../ecoute/custom_speech_recognition/__init__.py", line 208, in __exit__
    self.stream.close()
    ^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'close'

AudioRecorder.py Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@brimbela
Copy link

brimbela commented May 31, 2023

Great work @enemaliwilliam!
Got it running on my M1 Macbook, but nothing "happened".
I'm using a headset.
Any advice on the hardware setup?

Copy link

@flexbox flexbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@enemaliwilliam
Copy link
Author

Great work @enemaliwilliam! Got it running on my M1 Macbook, but nothing "happened". I'm using a headset. Any advice on the hardware setup?

can you change the index of your device ? line 55 of AudioRecorder.py

@brimbela
Copy link

I'm now trying with default speakers.
It should be ok:
>>> p.get_device_info_by_index(1) {'index': 1, 'structVersion': 2, 'name': 'MacBook Pro Microphone', 'hostApi': 0, 'maxInputChannels': 1, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.0336875, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.043020833333333335, 'defaultHighOutputLatency': 0.1, 'defaultSampleRate': 48000.0}
But nothing happens.
Will add some logging to understand a bit better whats going on.

@brimbela
Copy link

I'm now trying with default speakers. It should be ok: >>> p.get_device_info_by_index(1) {'index': 1, 'structVersion': 2, 'name': 'MacBook Pro Microphone', 'hostApi': 0, 'maxInputChannels': 1, 'maxOutputChannels': 0, 'defaultLowInputLatency': 0.0336875, 'defaultLowOutputLatency': 0.01, 'defaultHighInputLatency': 0.043020833333333335, 'defaultHighOutputLatency': 0.1, 'defaultSampleRate': 48000.0} But nothing happens. Will add some logging to understand a bit better whats going on.

Got it working. Added some logs to actually see the transcript and AI response and it's working.
What is not working for me is the UI.

@@ -20,6 +20,11 @@ Follow these steps to set up and run Ecoute on your local machine.
- Windows OS (Not tested on others)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add M1 macs here too :)

Copy link

@oldsongsz oldsongsz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree such hard coded way. the device index is variable to different compuaters and conditions. There should be more elegant solutions.

@SevaSk SevaSk self-requested a review May 31, 2023 20:59
Copy link
Owner

@SevaSk SevaSk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I've left some comments on your work. Unfortunately, I don't have any specific contributing guidelines to facilitate easier approval for your pull requests. However, I recommend following industry best practices and considering the feedback provided. Please feel free to express disagreements with the design decisions I've made. Although I may not always have time to assist directly, I will be sure to approve your changes when they align with my perspective or when you manage to change my mind.

from datetime import datetime
import os

if os.name == 'nt':
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Try to refactor to set up all differences between windows and MAC in one place. Dependency injection looks appropriate here open for other approach's to keep code clean.

break
else:
print("[ERROR] No loopback device found.")
if os.name == 'nt':
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DefaultSpeakerRecorder should be agnostic to operating system. Same as point 1)

from heapq import merge

if os.name == 'nt':
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as 1)



<details>
<summary>Windows</summary>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@@ -107,7 +107,10 @@ def get_pyaudio():
Imports the pyaudio module and checks its version. Throws exceptions if pyaudio can't be found or a wrong version is installed
"""
try:
import pyaudiowpatch as pyaudio
if os.name == 'nt':
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requirements.txt Show resolved Hide resolved
@vikkastaneja
Copy link

vikkastaneja commented Jun 1, 2023

pip install -r requirements.txt gives me the following error on macos with m1 chip.

  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /opt/homebrew/Caskroom/miniconda/base/include -arch arm64 -fPIC -O2 -isystem /opt/homebrew/Caskroom/miniconda/base/include -arch arm64 -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/opt/homebrew/Caskroom/miniconda/base/include/python3.10 -c src/pyaudio/device_api.c -o build/temp.macosx-11.1-arm64-cpython-310/src/pyaudio/device_api.o
  src/pyaudio/device_api.c:9:10: fatal error: 'portaudio.h' file not found
  #include "portaudio.h"
           ^~~~~~~~~~~~~
  1 error generated.
  error: command '/usr/bin/clang' failed with exit code 1
  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pyaudio
Building wheel for future (setup.py) ... done
Created wheel for future: filename=future-0.18.3-py3-none-any.whl size=492025 sha256=06a94a32594e49c131ae82646e552c9fa6fa61b527bb5881c4903dc4db0d2285
Stored in directory: /Users/vtaneja/Library/Caches/pip/wheels/5e/a9/47/f118e66afd12240e4662752cc22cefae5d97275623aa8ef57d
Successfully built openai-whisper Wave future
Failed to build pyaudio
ERROR: Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects

@enemaliwilliam
Copy link
Author

pip install -r requirements.txt gives me the following error on macos with m1 chip.

  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /opt/homebrew/Caskroom/miniconda/base/include -arch arm64 -fPIC -O2 -isystem /opt/homebrew/Caskroom/miniconda/base/include -arch arm64 -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/opt/homebrew/Caskroom/miniconda/base/include/python3.10 -c src/pyaudio/device_api.c -o build/temp.macosx-11.1-arm64-cpython-310/src/pyaudio/device_api.o
  src/pyaudio/device_api.c:9:10: fatal error: 'portaudio.h' file not found
  #include "portaudio.h"
           ^~~~~~~~~~~~~
  1 error generated.
  error: command '/usr/bin/clang' failed with exit code 1
  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for pyaudio Building wheel for future (setup.py) ... done Created wheel for future: filename=future-0.18.3-py3-none-any.whl size=492025 sha256=06a94a32594e49c131ae82646e552c9fa6fa61b527bb5881c4903dc4db0d2285 Stored in directory: /Users/vtaneja/Library/Caches/pip/wheels/5e/a9/47/f118e66afd12240e4662752cc22cefae5d97275623aa8ef57d Successfully built openai-whisper Wave future Failed to build pyaudio ERROR: Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects

You probably didn't install the portaudio using homebrew

@mrdavidlaing
Copy link

I couldn't get this to work on Mac M1 with Python v3.10.10.

This kept throwing the error:

RuntimeError: tk.h version (8.5) doesn't match libtk.a version (8.6)

I could however get it to work with an older Python version - v3.9.8

@ryanxjhan
Copy link

I got it running, and my UI is working fine on my M2 Pro. No errors whatsoever. But the app couldn't separate the speaker's words and mine. Everything is coming from [You]. I tried to change the get_device_info_by_index but it didn't work

@CyberNinja568
Copy link

Thanks for sharing your project on GitHub! It's impressive to see

@xiaotianxt
Copy link

I don't agree such hard coded way. the device index is variable to different compuaters and conditions. There should be more elegant solutions.

I totally agree with you. In fact, on my device (M2 MacBook Air), the code only works when the device index is set to 0, not 1. We definitely need to consider this variability in different setups.

@alabrashJr
Copy link

alabrashJr commented Jun 8, 2023

I attempted to run it on my Apple M1 Pro, but unfortunately, I encountered an error that I was unable to resolve despite my efforts. I followed the instructions provided in link, but the issue persisted. Do you have any recommendations for how I can resolve this error?

/Users/..../lib/python3.8/site-packages/whisper/timing.py:58: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.
  def backtrace(trace: np.ndarray):
Could not import the PyAudio C module 'pyaudio._portaudio'.
Traceback (most recent call last):
  File "main.py", line 2, in <module>
    from AudioTranscriber import AudioTranscriber
  File "/Users/.../ecoute/AudioTranscriber.py", line 15, in <module>
    import pyaudio
  File "/Users/...lib/python3.8/site-packages/pyaudio/__init__.py", line 111, in <module>
    import pyaudio._portaudio as pa
ImportError: dlopen(/Users/.../lib/python3.8/site-packages/pyaudio/_portaudio.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '_PaMacCore_SetupChannelMap'

versions:
Python 3.9.12
pip 23.1.2
pyaudio==0.2.13
Homebrew 4.0.21
Homebrew/homebrew-core (git revision 72cb0f2fe6d; last commit 2023-06-08)
Homebrew/homebrew-cask (git revision 9537303472; last commit 2023-06-08)

 brew info portaudio
==> portaudio: stable 19.7.0 (bottled), HEAD
Cross-platform library for audio I/O
http://www.portaudio.com
/opt/homebrew/Cellar/portaudio/HEAD-cb8d3dc (33 files, 546.7KB) *
  Built from source on 2023-06-08 at 18:31:58
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/portaudio.rb
License: MIT
==> Dependencies
Build: pkg-config ✔
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 7,874 (30 days), 1,289 (90 days), 73,904 (365 days)
install-on-request: 3,964 (30 days), 967 (90 days), 43,194 (365 days)
build-error: 0 (30 days)

@alabrashJr
Copy link

I attempted to run it on my Apple M1 Pro, but unfortunately, I encountered an error that I was unable to resolve despite my efforts. I followed the instructions provided in link, but the issue persisted. Do you have any recommendations for how I can resolve this error?

/Users/..../lib/python3.8/site-packages/whisper/timing.py:58: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.
  def backtrace(trace: np.ndarray):
Could not import the PyAudio C module 'pyaudio._portaudio'.
Traceback (most recent call last):
  File "main.py", line 2, in <module>
    from AudioTranscriber import AudioTranscriber
  File "/Users/.../ecoute/AudioTranscriber.py", line 15, in <module>
    import pyaudio
  File "/Users/...lib/python3.8/site-packages/pyaudio/__init__.py", line 111, in <module>
    import pyaudio._portaudio as pa
ImportError: dlopen(/Users/.../lib/python3.8/site-packages/pyaudio/_portaudio.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '_PaMacCore_SetupChannelMap'

versions: Python 3.9.12 pip 23.1.2 pyaudio==0.2.13 Homebrew 4.0.21 Homebrew/homebrew-core (git revision 72cb0f2fe6d; last commit 2023-06-08) Homebrew/homebrew-cask (git revision 9537303472; last commit 2023-06-08)

 brew info portaudio
==> portaudio: stable 19.7.0 (bottled), HEAD
Cross-platform library for audio I/O
http://www.portaudio.com
/opt/homebrew/Cellar/portaudio/HEAD-cb8d3dc (33 files, 546.7KB) *
  Built from source on 2023-06-08 at 18:31:58
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/portaudio.rb
License: MIT
==> Dependencies
Build: pkg-config ✔
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 7,874 (30 days), 1,289 (90 days), 73,904 (365 days)
install-on-request: 3,964 (30 days), 967 (90 days), 43,194 (365 days)
build-error: 0 (30 days)

I fixed the issue using the Python (v 3.11.3) I installed using brew

@notjulian
Copy link

notjulian commented Jun 20, 2023

this is amazing, works perfectly
M1 pro

followed this link to install pyaudio

and also:

brew install [email protected]

python3 --version
Python 3.11.4

@DavidAGInnovation
Copy link

Why is this not merged yet?

@ES-Anon
Copy link

ES-Anon commented Jul 3, 2023

Why is this not merged yet?

Likely because @SevaSk requested changes that haven't been addressed?

Thank you all for your work on this. Currently testing with my Intel MBP.

@xjqsusu
Copy link

xjqsusu commented Jul 16, 2023

I got it running, and my UI is working fine on my M2 Pro. No errors whatsoever. But the app couldn't separate the speaker's words and mine. Everything is coming from [You]. I tried to change the get_device_info_by_index but it didn't work

did you get this fixed? I'm seeing the same issue, which SPEAKER AND YOU are the same, reading the microphone input.

@FOkvj
Copy link

FOkvj commented Aug 6, 2023

on Intel5 mac
$ brew install portaudio
then
$ pip install pyaudio
done

@qartheeq
Copy link

qartheeq commented Aug 7, 2023

*/ecoute/AudioTranscriber.py", line 1, in
import whisper
ModuleNotFoundError: No module named 'whisper'

I am receiving this error

@vskrch
Copy link

vskrch commented Sep 16, 2023

*/ecoute/AudioTranscriber.py", line 1, in import whisper ModuleNotFoundError: No module named 'whisper'

I am receiving this error

try this:
pip install openai-whisper --no-cache-dir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet