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
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 20 additions & 12 deletions AudioRecorder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import custom_speech_recognition as sr
import pyaudiowpatch as pyaudio
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.

import pyaudiowpatch as pyaudio
else:
import pyaudio

RECORD_TIMEOUT = 3
ENERGY_THRESHOLD = 1000
Expand Down Expand Up @@ -34,17 +39,20 @@ def __init__(self):

class DefaultSpeakerRecorder(BaseRecorder):
def __init__(self):
with pyaudio.PyAudio() as p:
wasapi_info = p.get_host_api_info_by_type(pyaudio.paWASAPI)
default_speakers = p.get_device_info_by_index(wasapi_info["defaultOutputDevice"])

if not default_speakers["isLoopbackDevice"]:
for loopback in p.get_loopback_device_info_generator():
if default_speakers["name"] in loopback["name"]:
default_speakers = loopback
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)

with pyaudio.PyAudio() as p:
wasapi_info = p.get_host_api_info_by_type(pyaudio.paWASAPI)
default_speakers = p.get_device_info_by_index(wasapi_info["defaultOutputDevice"])
if not default_speakers["isLoopbackDevice"]:
for loopback in p.get_loopback_device_info_generator():
if default_speakers["name"] in loopback["name"]:
default_speakers = loopback
break
else:
print("[ERROR] No loopback device found.")
else:
p = pyaudio.PyAudio()
default_speakers = p.get_device_info_by_index(0)
enemaliwilliam marked this conversation as resolved.
Show resolved Hide resolved

source = sr.Microphone(speaker=True,
device_index= default_speakers["index"],
Expand Down
7 changes: 6 additions & 1 deletion AudioTranscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import custom_speech_recognition as sr
import io
from datetime import timedelta
import pyaudiowpatch as pyaudio
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)

import pyaudiowpatch as pyaudio
else:
import pyaudio


PHRASE_TIMEOUT = 3.05

MAX_PHRASES = 10
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ choco install ffmpeg-full
```
Please ensure that you run these commands in a PowerShell window with administrator privileges. If you face any issues during the installation, you can visit the official Chocolatey and FFmpeg websites for troubleshooting.

To run on mac os, please install the following
enemaliwilliam marked this conversation as resolved.
Show resolved Hide resolved
`brew install portaudio`
`brew install python-tk `

### 🔧 Installation

1. Clone the repository:
Expand Down Expand Up @@ -60,6 +64,7 @@ Please ensure that you run these commands in a PowerShell window with administra

Replace `API KEY` with your actual OpenAI API key.


### 🎬 Running Ecoute

Run the main script:
Expand Down
5 changes: 4 additions & 1 deletion custom_speech_recognition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

import pyaudiowpatch as pyaudio
else:
import pyaudio
except ImportError:
raise AttributeError("Could not find PyAudio; check installation")
from distutils.version import LooseVersion
Expand Down
7 changes: 5 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ openai-whisper==20230314
Wave==0.0.2
openai==0.27.6
customtkinter==5.1.3
PyAudioWPatch==0.2.12.5
--extra-index-url https://download.pytorch.org/whl/cu117
torch
torch
enemaliwilliam marked this conversation as resolved.
Show resolved Hide resolved

# Windows-specific dependencies
PyAudioWPatch==0.2.12.5; platform_system == "Windows"
pyaudio; platform_system != "Windows"