diff --git a/AudioRecorder.py b/AudioRecorder.py index 8c09227..5fd495a 100644 --- a/AudioRecorder.py +++ b/AudioRecorder.py @@ -1,5 +1,5 @@ import custom_speech_recognition as sr -import pyaudiowpatch as pyaudio +import pyaudio from datetime import datetime RECORD_TIMEOUT = 3 @@ -38,22 +38,20 @@ class DefaultMicRecorder(BaseRecorder): 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.") + p = pyaudio.PyAudio() - source = sr.Microphone(speaker=True, - device_index= default_speakers["index"], - sample_rate=int(default_speakers["defaultSampleRate"]), - chunk_size=pyaudio.get_sample_size(pyaudio.paInt16), - channels=default_speakers["maxInputChannels"]) + # Get default input device information + default_input_device_info = p.get_default_input_device_info() + + source = sr.Microphone( + device_index=default_input_device_info["index"], + sample_rate=int(default_input_device_info["defaultSampleRate"]), + chunk_size=pyaudio.get_sample_size(pyaudio.paInt16), + channels=default_input_device_info["maxInputChannels"] + ) super().__init__(source=source, source_name="Speaker") - self.adjust_for_noise("Default Speaker", "Please make or play some noise from the Default Speaker...") \ No newline at end of file + self.adjust_for_noise("Default Speaker", "Please make or play some noise from the Default Speaker...") + + # Don't forget to close PyAudio object when you're done + p.terminate() + diff --git a/AudioTranscriber.py b/AudioTranscriber.py index b37eae8..d6ed927 100644 --- a/AudioTranscriber.py +++ b/AudioTranscriber.py @@ -7,7 +7,7 @@ import tempfile import custom_speech_recognition as sr import io from datetime import timedelta -import pyaudiowpatch as pyaudio +import pyaudio from heapq import merge PHRASE_TIMEOUT = 3.05 diff --git a/README.md b/README.md index e7eaa6c..87ee7dd 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Follow these steps to set up and run Ecoute on your local machine. ### 📋 Prerequisites - Python >=3.8.0 -- An OpenAI API key that can access OpenAI API (set up a paid account OpenAI account) +- An OpenAI API key - Windows OS (Not tested on others) - FFmpeg diff --git a/custom_speech_recognition/__init__.py b/custom_speech_recognition/__init__.py index 1d339b0..cd324f2 100644 --- a/custom_speech_recognition/__init__.py +++ b/custom_speech_recognition/__init__.py @@ -107,7 +107,7 @@ class Microphone(AudioSource): 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 + import pyaudio except ImportError: raise AttributeError("Could not find PyAudio; check installation") from distutils.version import LooseVersion diff --git a/requirements.txt b/requirements.txt index 78f1554..b2f8d55 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,6 @@ 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 +PyAudio # for Mac +# --extra-index-url https://download.pytorch.org/whl/cu117 torch \ No newline at end of file