voice-changer/server/voice_changer/IORecorder.py
w-okada 75668e1534 Bugfix:
- device output recorder button is showed in server device mode.
Feature:
 - server device monitor
Improve:
 - default uvicorn error log
2023-07-01 14:57:57 +09:00

36 lines
1.0 KiB
Python

import wave
import os
class IORecorder:
def __init__(self, inputFilename: str, outputFilename: str, inputSamplingRate: int, outputSamplingRate: int):
self._clearFile(inputFilename)
self._clearFile(outputFilename)
self.fi = wave.open(inputFilename, "wb")
self.fi.setnchannels(1)
self.fi.setsampwidth(2)
self.fi.setframerate(inputSamplingRate)
self.fo = wave.open(outputFilename, "wb")
self.fo.setnchannels(1)
self.fo.setsampwidth(2)
self.fo.setframerate(outputSamplingRate)
def _clearFile(self, filename: str):
if os.path.exists(filename):
print("[IORecorder] delete old analyze file.", filename)
os.remove(filename)
else:
print("[IORecorder] old analyze file not exist.", filename)
def writeInput(self, wav):
self.fi.writeframes(wav)
def writeOutput(self, wav):
self.fo.writeframes(wav)
def close(self):
self.fi.close()
self.fo.close()