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

Resolve setup issues for macOS (Venture 13.4): pyaudiowpatch -> pyaud… #91

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
38 changes: 27 additions & 11 deletions AudioRecorder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import custom_speech_recognition as sr
import pyaudiowpatch as pyaudio
#import pyaudiowpatch as pyaudio
import pyaudio
from datetime import datetime

RECORD_TIMEOUT = 3
Expand Down Expand Up @@ -38,22 +39,37 @@ 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)
#with pyaudio.PyAudio() as p:
p = pyaudio.PyAudio()
try:
#wasapi_info = p.get_host_api_info_by_type(pyaudio.paWASAPI)
wasapi_info = p.get_host_api_info_by_type(pyaudio.paCoreAudio)

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
#if not default_speakers["isLoopbackDevice"]:
if not default_speakers.get("isLoopbackDevice", False):

for i in range(p.get_device_count()):
device_info = p.get_device_info_by_index(i)
if device_info['maxInputChannels'] > 0 and device_info['hostApi'] == p.get_default_host_api_info()['index']:
default_speakers = loopback = device_info
break
else:
print("[ERROR] No loopback device found.")

else:
print("[ERROR] No loopback device found.")

# 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.")
finally:
p.terminate()
mlubbad marked this conversation as resolved.
Show resolved Hide resolved
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")
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...")
5 changes: 3 additions & 2 deletions AudioTranscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import custom_speech_recognition as sr
import io
from datetime import timedelta
import pyaudiowpatch as pyaudio
#import pyaudiowpatch as pyaudio
import pyaudio
from heapq import merge

PHRASE_TIMEOUT = 3.05
Expand Down Expand Up @@ -112,4 +113,4 @@ def clear_transcript_data(self):
self.audio_sources["Speaker"]["last_sample"] = bytes()

self.audio_sources["You"]["new_phrase"] = True
self.audio_sources["Speaker"]["new_phrase"] = True
self.audio_sources["Speaker"]["new_phrase"] = True
3 changes: 2 additions & 1 deletion custom_speech_recognition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ 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
#import pyaudiowpatch as pyaudio
import pyaudio
except ImportError:
raise AttributeError("Could not find PyAudio; check installation")
from distutils.version import LooseVersion
Expand Down