mirror of
https://github.com/SevaSk/ecoute.git
synced 2024-12-25 07:11:02 +00:00
MacOS Adaptation: Switched from PyAudioWPatch to PyAudio, Refined for Core Audio, Discontinued Windows Compatibility
This commit is contained in:
parent
7264e73508
commit
bdd7aff9a1
@ -1,5 +1,5 @@
|
|||||||
import custom_speech_recognition as sr
|
import custom_speech_recognition as sr
|
||||||
import pyaudiowpatch as pyaudio
|
import pyaudio
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
RECORD_TIMEOUT = 3
|
RECORD_TIMEOUT = 3
|
||||||
@ -38,22 +38,12 @@ class DefaultMicRecorder(BaseRecorder):
|
|||||||
|
|
||||||
class DefaultSpeakerRecorder(BaseRecorder):
|
class DefaultSpeakerRecorder(BaseRecorder):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
with pyaudio.PyAudio() as p:
|
p = pyaudio.PyAudio()
|
||||||
wasapi_info = p.get_host_api_info_by_type(pyaudio.paWASAPI)
|
try:
|
||||||
default_speakers = p.get_device_info_by_index(wasapi_info["defaultOutputDevice"])
|
# Use the default input device as the audio source
|
||||||
|
default_device_index = p.get_default_input_device_info()["index"]
|
||||||
if not default_speakers["isLoopbackDevice"]:
|
source = sr.Microphone(device_index=default_device_index)
|
||||||
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.")
|
|
||||||
|
|
||||||
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"])
|
|
||||||
super().__init__(source=source, source_name="Speaker")
|
super().__init__(source=source, source_name="Speaker")
|
||||||
self.adjust_for_noise("Default Speaker", "Please make or play some noise from the Default Speaker...")
|
self.adjust_for_noise("Default Speaker", "Please make or play some noise from the Default Speaker...")
|
||||||
|
finally:
|
||||||
|
p.terminate()
|
||||||
|
@ -7,7 +7,7 @@ import tempfile
|
|||||||
import custom_speech_recognition as sr
|
import custom_speech_recognition as sr
|
||||||
import io
|
import io
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import pyaudiowpatch as pyaudio
|
import pyaudio
|
||||||
from heapq import merge
|
from heapq import merge
|
||||||
|
|
||||||
PHRASE_TIMEOUT = 3.05
|
PHRASE_TIMEOUT = 3.05
|
||||||
|
@ -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
|
Imports the pyaudio module and checks its version. Throws exceptions if pyaudio can't be found or a wrong version is installed
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
import pyaudiowpatch as pyaudio
|
import pyaudio
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise AttributeError("Could not find PyAudio; check installation")
|
raise AttributeError("Could not find PyAudio; check installation")
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
|
@ -3,6 +3,6 @@ openai-whisper==20230314
|
|||||||
Wave==0.0.2
|
Wave==0.0.2
|
||||||
openai==0.27.6
|
openai==0.27.6
|
||||||
customtkinter==5.1.3
|
customtkinter==5.1.3
|
||||||
PyAudioWPatch==0.2.12.5
|
pyaudio==0.2.14
|
||||||
--extra-index-url https://download.pytorch.org/whl/cu117
|
--extra-index-url https://download.pytorch.org/whl/cu117
|
||||||
torch
|
torch
|
Loading…
Reference in New Issue
Block a user