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 all commits
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(1)

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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :)

- FFmpeg




<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!

If FFmpeg is not installed in your system, you can follow the steps below to install it.

First, you need to install Chocolatey, a package manager for Windows. Open your PowerShell as Administrator and run the following command:
Expand All @@ -31,6 +36,20 @@ Once Chocolatey is installed, you can install FFmpeg by running the following co
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.
</details>

<details>
<summary>macOS</summary>
If FFmpeg is not installed in your system, you can follow the steps below to install it.

brew install ffmpeg
brew install portaudio
brew install python-tk

You might need to change the index of your speaker depending on your setting to 0 or 1
on line 55 AudioRecorder.py

</details>

### 🔧 Installation

Expand Down Expand Up @@ -67,6 +86,7 @@ Please ensure that you run these commands in a PowerShell window with administra
```
Replace "API KEY" with your actual OpenAI API key. Save this file as keys.py within the ecoute directory.


### 🎬 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"