Reverting sound recording to wav.

This commit is contained in:
jpunkt 2021-11-04 15:04:12 +01:00
parent 4555d1ad89
commit fd1fa138d9

View file

@ -4,7 +4,7 @@ from time import sleep
from enum import Enum
from typing import Any, List
# from scipy.io.wavfile import write as writewav
from scipy.io.wavfile import write as writewav
import pydub
import sounddevice as sd
@ -215,10 +215,10 @@ def record_sound(hal: PizzaHAL, filename: Any, duration: int,
else:
sd.wait() # Wait until recording is finished
# TODO test
myrecording = np.int16(myrecording)
song = pydub.AudioSegment(myrecording.tobytes(), frame_rate=AUDIO_REC_SR, sample_width=2, channels=2)
song.export(str(filename), format="mp3", bitrate="320k")
# ALTERNATIVE writewav(str(filename), AUDIO_REC_SR, myrecording)
# myrecording = np.int16(myrecording)
# song = pydub.AudioSegment(myrecording.tobytes(), frame_rate=AUDIO_REC_SR, sample_width=2, channels=2)
# song.export(str(filename), format="mp3", bitrate="44.1k")
writewav(str(filename), AUDIO_REC_SR, myrecording)
if cache:
hal.soundcache[str(filename)] = (myrecording, AUDIO_REC_SR)