8000 MacOS Adaptation: Switched from PyAudioWPatch to PyAudio by Mahmoudz · Pull Request #164 · SevaSk/ecoute · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MacOS Adaptation: Switched from PyAudioWPatch to PyAudio 8000 #164

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

Open
wants to merge 1 commit 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions AudioRecorder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import custom_speech_recognition as sr
import pyaudiowpatch as pyaudio
import pyaudio
from datetime import datetime

RECORD_TIMEOUT = 3
Expand Down Expand Up @@ -38,22 +38,12 @@ 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.")

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...")
p = pyaudio.PyAudio()
try:
# Use the default input device as the audio source
default_device_index = p.get_default_input_device_info()["index"]
source = sr.Microphone(device_index=default_device_index)
super().__init__(source=source, source_name="Speaker")
self.adjust_for_noise("Default Speaker", "Please make or play some noise from the Default Speaker...")
finally:
p.terminate()
2 changes: 1 addition & 1 deletion AudioTranscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion custom_speech_recognition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ 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 pyaudio
except ImportError:
raise AttributeError("Could not find PyAudio; check installation")
from distutils.version import LooseVersion
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ openai-whisper==20230314
Wave==0.0.2
openai==0.27.6
customtkinter==5.1.3
PyAudioWPatch==0.2.12.5
pyaudio==0.2.14
--extra-index-url https://download.pytorch.org/whl/cu117
torch
torch
0