aboutsummaryrefslogtreecommitdiffstats
path: root/solo-tool-project/src
diff options
context:
space:
mode:
Diffstat (limited to 'solo-tool-project/src')
-rw-r--r--solo-tool-project/src/solo_tool/recorder.py36
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):