diff options
| author | Eddy Pedroni <epedroni@pm.me> | 2026-01-01 18:46:36 +0100 |
|---|---|---|
| committer | Eddy Pedroni <epedroni@pm.me> | 2026-01-01 18:46:36 +0100 |
| commit | 328019b5a98b6effea22434733da42b72a1797ed (patch) | |
| tree | 35cd2264eb9dad31ca4aca6cb34ea2b67ab7af8a /solo-tool-project | |
| parent | e2e237b082d750e14a1630fd2ac3c90723b33cdb (diff) | |
Diffstat (limited to 'solo-tool-project')
| -rw-r--r-- | solo-tool-project/src/solo_tool/recorder.py | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/solo-tool-project/src/solo_tool/recorder.py b/solo-tool-project/src/solo_tool/recorder.py index fd2df02..f73f51e 100644 --- a/solo-tool-project/src/solo_tool/recorder.py +++ b/solo-tool-project/src/solo_tool/recorder.py @@ -1,30 +1,26 @@ -import pyaudio as pa from pathlib import Path +import pyaudio as pa +from pydub import AudioSegment, effects + class Recording: - def __init__(self, frames: [], channels: int, samplingRate: int, sampleFormat: int): - self._frames = frames - self._channels = channels - self._samplingRate = samplingRate - self._sampleFormat = sampleFormat + def __init__(self, frames: list, channels: int, samplingRate: int, sampleFormat: int): + self._segment = AudioSegment( + data=b''.join(frames), + sample_width=sampleFormat, + frame_rate=samplingRate, + channels=channels + ) + self._postProcess() + + def _postProcess(self) -> None: + self._segment = effects.normalize(self._segment) def writeWav(self, file: Path) -> None: - import wave - with wave.open(str(file), "wb") as wf: - wf.setnchannels(self._channels) - wf.setsampwidth(self._sampleFormat) - wf.setframerate(self._samplingRate) - wf.writeframes(b''.join(self._frames)) + self._segment.export(str(file), format="wav") def writeMp3(self, file: Path) -> None: - from pydub import AudioSegment - segment = AudioSegment( - data=b''.join(self._frames), - sample_width=self._sampleFormat, - frame_rate=self._samplingRate, - channels=self._channels - ) - segment.export(str(file), format="mp3", bitrate="320k") + self._segment.export(str(file), format="mp3", bitrate="320k") class Recorder: def __init__(self, bufferSize: int, samplingRate: int): |
