Recorder can log without recording voice
This commit is contained in:
parent
16fbee7555
commit
c3cae1ea25
1 changed files with 19 additions and 18 deletions
|
@ -50,25 +50,23 @@ class Recorder:
|
||||||
|
|
||||||
|
|
||||||
def writeData(self):
|
def writeData(self):
|
||||||
if len(self.data) < 1:
|
|
||||||
self.logger.info("Skip empty wave creation")
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
if self.record_voice:
|
if self.record_voice:
|
||||||
self.fragmentNr += 1
|
if len(self.data) < 1:
|
||||||
|
self.logger.info("Skip empty wave creation")
|
||||||
|
else:
|
||||||
|
self.fragmentNr += 1
|
||||||
|
|
||||||
fn = os.path.join(self.out_folder, f"{self.fragmentNr}.wav")
|
fn = os.path.join(self.out_folder, f"{self.fragmentNr}.wav")
|
||||||
|
|
||||||
self.logger.info(f"Write wave: {fn}")
|
self.logger.info(f"Write wave: {fn}")
|
||||||
|
|
||||||
self.wf = wave.open(fn, 'wb')
|
self.wf = wave.open(fn, 'wb')
|
||||||
self.wf.setnchannels(1)
|
self.wf.setnchannels(1)
|
||||||
self.wf.setsampwidth(2)
|
self.wf.setsampwidth(2)
|
||||||
self.wf.setframerate(self.src_rate)
|
self.wf.setframerate(self.src_rate)
|
||||||
# adapted from https://stackoverflow.com/questions/892199/detect-record-audio-in-python#6743593
|
# adapted from https://stackoverflow.com/questions/892199/detect-record-audio-in-python#6743593
|
||||||
self.wf.writeframes(pack('<' + ('h'*len(self.data)), *self.data))
|
self.wf.writeframes(pack('<' + ('h'*len(self.data)), *self.data))
|
||||||
self.wf.close()
|
self.wf.close()
|
||||||
|
|
||||||
with open(os.path.join(self.out_folder, "transcriptions.txt"), "a") as fp:
|
with open(os.path.join(self.out_folder, "transcriptions.txt"), "a") as fp:
|
||||||
fp.write(f"{self.fragmentNr}\t{self.currentTranscription}\n")
|
fp.write(f"{self.fragmentNr}\t{self.currentTranscription}\n")
|
||||||
|
@ -79,9 +77,6 @@ class Recorder:
|
||||||
self.currentTranscription = ""
|
self.currentTranscription = ""
|
||||||
|
|
||||||
def receive(self, chunk):
|
def receive(self, chunk):
|
||||||
if not self.record_voice:
|
|
||||||
return
|
|
||||||
|
|
||||||
if not self.running:
|
if not self.running:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -100,6 +95,12 @@ class Recorder:
|
||||||
else:
|
else:
|
||||||
self.subsequentMutedFrames = 0
|
self.subsequentMutedFrames = 0
|
||||||
|
|
||||||
|
|
||||||
|
if not self.record_voice:
|
||||||
|
# we only check this here, as the writeData above is used to write
|
||||||
|
# transcriptions to the log.
|
||||||
|
return
|
||||||
|
|
||||||
d = array('h', chunk)
|
d = array('h', chunk)
|
||||||
self.data.extend(d)
|
self.data.extend(d)
|
||||||
# self.wf.writeframes(chunk)
|
# self.wf.writeframes(chunk)
|
||||||
|
|
Loading…
Reference in a new issue