aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--solo-tool-project/src/solo_tool/metronome.py6
-rw-r--r--solo-tool-project/src/solo_tool/recorder.py6
-rw-r--r--solo-tool-project/src/solo_tool/utils.py7
-rw-r--r--web-project/src/solo_tool_web.py13
4 files changed, 24 insertions, 8 deletions
diff --git a/solo-tool-project/src/solo_tool/metronome.py b/solo-tool-project/src/solo_tool/metronome.py
index 9c65357..3ffc6bc 100644
--- a/solo-tool-project/src/solo_tool/metronome.py
+++ b/solo-tool-project/src/solo_tool/metronome.py
@@ -1,6 +1,8 @@
import pyaudio as pa
from array import array
+from solo_tool.utils import getAudioDeviceIndex
+
def _createClickSample(clickFrequency: int, samplingRate: int) -> array:
clickDuration = 0.03 # seconds
@@ -22,9 +24,10 @@ def _createOutputBuffer(bpm: int, clickFrequency: int, samplingRate: int) -> arr
return clickSample + array('h', [0] * (samplesPerBeat - len(clickSample)))
class Metronome:
- def __init__(self, bufferSize: int, samplingRate: int):
+ def __init__(self, bufferSize: int, samplingRate: int, deviceName: str):
self._bufferSize = bufferSize
self._samplingRate = samplingRate
+ self._deviceName = deviceName
self._sampleFormat = pa.paInt16
self._channels = 1
self._pa = pa.PyAudio()
@@ -58,6 +61,7 @@ class Metronome:
rate=self._samplingRate,
frames_per_buffer=self._bufferSize,
output=True,
+ output_device_index=getAudioDeviceIndex(self._deviceName, self._pa),
stream_callback=self._callback)
def stop(self) -> None:
diff --git a/solo-tool-project/src/solo_tool/recorder.py b/solo-tool-project/src/solo_tool/recorder.py
index 71c8ac8..c628832 100644
--- a/solo-tool-project/src/solo_tool/recorder.py
+++ b/solo-tool-project/src/solo_tool/recorder.py
@@ -3,6 +3,8 @@ from pathlib import Path
import pyaudio as pa
from pydub import AudioSegment, effects
+from solo_tool.utils import getAudioDeviceIndex
+
class Recording:
def __init__(self, frames: list, channels: int, samplingRate: int, sampleFormat: int):
self._segment = AudioSegment(
@@ -23,9 +25,10 @@ class Recording:
self._segment.export(str(file), format="mp3", bitrate="320k")
class Recorder:
- def __init__(self, bufferSize: int, samplingRate: int):
+ def __init__(self, bufferSize: int, samplingRate: int, deviceName: str):
self._bufferSize = bufferSize
self._samplingRate = samplingRate
+ self._deviceName = deviceName
self._sampleFormat = pa.paInt16
self._channels = 2
self._pa = pa.PyAudio()
@@ -56,6 +59,7 @@ class Recorder:
rate=self._samplingRate,
frames_per_buffer=self._bufferSize,
input=True,
+ input_device_index=getAudioDeviceIndex(self._deviceName, self._pa),
stream_callback=self._callback)
def stopRecording(self) -> Recording:
diff --git a/solo-tool-project/src/solo_tool/utils.py b/solo-tool-project/src/solo_tool/utils.py
new file mode 100644
index 0000000..df39fd9
--- /dev/null
+++ b/solo-tool-project/src/solo_tool/utils.py
@@ -0,0 +1,7 @@
+from pyaudio import PyAudio
+
+def getAudioDeviceIndex(name: str, pa: PyAudio) -> int:
+ for i in range(pa.get_device_count()):
+ if pa.get_device_info_by_index(i)["name"].startswith(name):
+ return i
+ raise Exception(f"Audio device not found: {name}")
diff --git a/web-project/src/solo_tool_web.py b/web-project/src/solo_tool_web.py
index 0315816..49cddcd 100644
--- a/web-project/src/solo_tool_web.py
+++ b/web-project/src/solo_tool_web.py
@@ -180,11 +180,11 @@ def landingPage():
for id, soloTool in sessions.items():
ui.button(id, on_click=partial(ui.navigate.to, f"/{id}"))
-def start(port, refresh, reload, sessionPath, bufferSize, samplingRate):
+def start(port, refresh, reload, sessionPath, bufferSize, samplingRate, deviceName):
global sessionManager, recorder, metronome, volumeController
sessionManager = SessionManager(sessionPath)
- recorder = Recorder(bufferSize, samplingRate)
- metronome = Metronome(bufferSize, samplingRate)
+ recorder = Recorder(bufferSize, samplingRate, deviceName)
+ metronome = Metronome(bufferSize, samplingRate, deviceName)
volumeController = VolumeControllerXR18("XR18-7EE3D3.0xf7.com")
for id in sessionManager.getSessions():
@@ -205,10 +205,11 @@ def start(port, refresh, reload, sessionPath, bufferSize, samplingRate):
@click.option("--session_path", default="https://files.0xf7.com", help="Look for sessions in this location.")
@click.option("--buffer_size", type=int, default=128, help="Audio buffer size for recording.")
@click.option("--sampling_rate", type=int, default=48000, help="Audio sampling rate for recording.")
-def main(port, refresh, reload, session_path, buffer_size, sampling_rate):
- start(port, refresh, reload, session_path, buffer_size, sampling_rate)
+@click.option("--device_name", type=str, default="XR18", help="Audio device for recording.")
+def main(port, refresh, reload, session_path, buffer_size, sampling_rate, device_name):
+ start(port, refresh, reload, session_path, buffer_size, sampling_rate, device_name)
# Hardcoded dev settings
if __name__ in {"__main__", "__mp_main__"}:
- start(8080, 0.5, True, "https://files.0xf7.com", 1024, 48000)
+ start(8080, 0.5, True, "https://files.0xf7.com", 1024, 48000, "pipewire")
#start(8080, 0.5, True, "/home/eddy/music", 1024, 48000)