Allow logging without voice
This commit is contained in:
parent
be10bfe44c
commit
28d8d26ce7
3 changed files with 58 additions and 47 deletions
|
@ -756,7 +756,9 @@ class HugveyState(object):
|
||||||
if self.command.config['voice']['record_dir']:
|
if self.command.config['voice']['record_dir']:
|
||||||
self.logger.warn("Record Audio of conversation")
|
self.logger.warn("Record Audio of conversation")
|
||||||
self.recorder = Recorder( self.id,
|
self.recorder = Recorder( self.id,
|
||||||
self.command.config['voice']['src_rate'], self.command.config['voice']['record_dir'])
|
self.command.config['voice']['src_rate'], self.command.config['voice']['record_dir'],
|
||||||
|
self.command.config['voice']['record_voice'] if 'record_voice' in self.command.config['voice'] else False)
|
||||||
|
|
||||||
self.streamer.addConsumer(self.recorder)
|
self.streamer.addConsumer(self.recorder)
|
||||||
|
|
||||||
self.logger.debug("Start Speech")
|
self.logger.debug("Start Speech")
|
||||||
|
|
|
@ -16,7 +16,7 @@ class Recorder:
|
||||||
Record the streamed audio
|
Record the streamed audio
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, hv_id, src_rate, out_folder):
|
def __init__(self, hv_id, src_rate, out_folder, record_voice = True):
|
||||||
self.logger = mainLogger.getChild(f"{hv_id}").getChild('recorder')
|
self.logger = mainLogger.getChild(f"{hv_id}").getChild('recorder')
|
||||||
|
|
||||||
if not os.path.exists(out_folder):
|
if not os.path.exists(out_folder):
|
||||||
|
@ -26,6 +26,7 @@ class Recorder:
|
||||||
self.src_rate = src_rate
|
self.src_rate = src_rate
|
||||||
self.main_folder = out_folder # unfortunately not every device plays 16kHz audio streams
|
self.main_folder = out_folder # unfortunately not every device plays 16kHz audio streams
|
||||||
self.running = False
|
self.running = False
|
||||||
|
self.record_voice = record_voice
|
||||||
self.data = array('h')
|
self.data = array('h')
|
||||||
self.currentLog = []
|
self.currentLog = []
|
||||||
|
|
||||||
|
@ -53,28 +54,34 @@ class Recorder:
|
||||||
self.logger.info("Skip empty wave creation")
|
self.logger.info("Skip empty wave creation")
|
||||||
return
|
return
|
||||||
|
|
||||||
self.fragmentNr += 1
|
|
||||||
|
|
||||||
fn = os.path.join(self.out_folder, f"{self.fragmentNr}.wav")
|
if self.record_voice:
|
||||||
|
self.fragmentNr += 1
|
||||||
|
|
||||||
self.logger.info(f"Write wave: {fn}")
|
fn = os.path.join(self.out_folder, f"{self.fragmentNr}.wav")
|
||||||
|
|
||||||
self.wf = wave.open(fn, 'wb')
|
self.logger.info(f"Write wave: {fn}")
|
||||||
self.wf.setnchannels(1)
|
|
||||||
self.wf.setsampwidth(2)
|
self.wf = wave.open(fn, 'wb')
|
||||||
self.wf.setframerate(self.src_rate)
|
self.wf.setnchannels(1)
|
||||||
# adapted from https://stackoverflow.com/questions/892199/detect-record-audio-in-python#6743593
|
self.wf.setsampwidth(2)
|
||||||
self.wf.writeframes(pack('<' + ('h'*len(self.data)), *self.data))
|
self.wf.setframerate(self.src_rate)
|
||||||
self.wf.close()
|
# 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.close()
|
||||||
|
|
||||||
|
with open(os.path.join(self.out_folder, "transcriptions.txt"), "a") as fp:
|
||||||
|
fp.write(f"{self.fragmentNr}\t{self.currentTranscription}\n")
|
||||||
|
|
||||||
with open(os.path.join(self.out_folder, "transcriptions.txt"), "a") as fp:
|
|
||||||
fp.write(f"{self.fragmentNr}\t{self.currentTranscription}\n")
|
|
||||||
self.log('-',self.currentTranscription)
|
self.log('-',self.currentTranscription)
|
||||||
|
|
||||||
self.data = array('h')
|
self.data = array('h')
|
||||||
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
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ voice:
|
||||||
port: 4444
|
port: 4444
|
||||||
chunk: 2972
|
chunk: 2972
|
||||||
google_credentials: "../test_googlespeech/My First Project-0c7833e0d5fa.json"
|
google_credentials: "../test_googlespeech/My First Project-0c7833e0d5fa.json"
|
||||||
|
record_dir: "./recordings"
|
||||||
|
record_voice: false
|
||||||
hugveys: 26
|
hugveys: 26
|
||||||
languages:
|
languages:
|
||||||
- code: en-GB
|
- code: en-GB
|
||||||
|
|
Loading…
Reference in a new issue