🐛[bugfix] Model: mic/speakerの音声入力処理のThreadの処理を修正(energyはまだ)
This commit is contained in:
38
model.py
38
model.py
@@ -36,19 +36,17 @@ class threadFnc(Thread):
|
|||||||
super(threadFnc, self).__init__(daemon=daemon, *args, **kwargs)
|
super(threadFnc, self).__init__(daemon=daemon, *args, **kwargs)
|
||||||
self.fnc = fnc
|
self.fnc = fnc
|
||||||
self.end_fnc = end_fnc
|
self.end_fnc = end_fnc
|
||||||
self._stop = Event()
|
self.loop = True
|
||||||
def stop(self):
|
|
||||||
self._stop.set()
|
|
||||||
def stopped(self):
|
|
||||||
return self._stop.is_set()
|
|
||||||
def run(self):
|
|
||||||
while True:
|
|
||||||
if self.stopped():
|
|
||||||
if callable(self.end_fnc):
|
|
||||||
self.end_fnc()
|
|
||||||
return
|
|
||||||
self.fnc(*self._args, **self._kwargs)
|
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self.loop = False
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
while self.loop:
|
||||||
|
self.fnc(*self._args, **self._kwargs)
|
||||||
|
if callable(self.end_fnc):
|
||||||
|
self.end_fnc()
|
||||||
|
return
|
||||||
class Model:
|
class Model:
|
||||||
_instance = None
|
_instance = None
|
||||||
|
|
||||||
@@ -392,9 +390,10 @@ class Model:
|
|||||||
)
|
)
|
||||||
def sendMicTranscript():
|
def sendMicTranscript():
|
||||||
try:
|
try:
|
||||||
self.mic_transcriber.transcribeAudioQueue(mic_audio_queue, config.SOURCE_LANGUAGE, config.SOURCE_COUNTRY)
|
res = self.mic_transcriber.transcribeAudioQueue(mic_audio_queue, config.SOURCE_LANGUAGE, config.SOURCE_COUNTRY)
|
||||||
message = self.mic_transcriber.getTranscript()
|
if res:
|
||||||
fnc(message)
|
message = self.mic_transcriber.getTranscript()
|
||||||
|
fnc(message)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -425,6 +424,7 @@ class Model:
|
|||||||
def stopMicTranscript(self):
|
def stopMicTranscript(self):
|
||||||
if isinstance(self.mic_print_transcript, threadFnc):
|
if isinstance(self.mic_print_transcript, threadFnc):
|
||||||
self.mic_print_transcript.stop()
|
self.mic_print_transcript.stop()
|
||||||
|
self.mic_print_transcript.join()
|
||||||
self.mic_print_transcript = None
|
self.mic_print_transcript = None
|
||||||
if isinstance(self.mic_audio_recorder, SelectedMicEnergyAndAudioRecorder):
|
if isinstance(self.mic_audio_recorder, SelectedMicEnergyAndAudioRecorder):
|
||||||
self.mic_audio_recorder.stop()
|
self.mic_audio_recorder.stop()
|
||||||
@@ -505,9 +505,10 @@ class Model:
|
|||||||
)
|
)
|
||||||
def sendSpeakerTranscript():
|
def sendSpeakerTranscript():
|
||||||
try:
|
try:
|
||||||
self.speaker_transcriber.transcribeAudioQueue(speaker_audio_queue, config.TARGET_LANGUAGE, config.TARGET_COUNTRY)
|
res = self.speaker_transcriber.transcribeAudioQueue(speaker_audio_queue, config.TARGET_LANGUAGE, config.TARGET_COUNTRY)
|
||||||
message = self.speaker_transcriber.getTranscript()
|
if res:
|
||||||
fnc(message)
|
message = self.speaker_transcriber.getTranscript()
|
||||||
|
fnc(message)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -538,6 +539,7 @@ class Model:
|
|||||||
def stopSpeakerTranscript(self):
|
def stopSpeakerTranscript(self):
|
||||||
if isinstance(self.speaker_print_transcript, threadFnc):
|
if isinstance(self.speaker_print_transcript, threadFnc):
|
||||||
self.speaker_print_transcript.stop()
|
self.speaker_print_transcript.stop()
|
||||||
|
self.speaker_print_transcript.join()
|
||||||
self.speaker_print_transcript = None
|
self.speaker_print_transcript = None
|
||||||
if isinstance(self.speaker_audio_recorder, SelectedSpeakerEnergyAndAudioRecorder):
|
if isinstance(self.speaker_audio_recorder, SelectedSpeakerEnergyAndAudioRecorder):
|
||||||
self.speaker_audio_recorder.stop()
|
self.speaker_audio_recorder.stop()
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import time
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from threading import Event
|
from threading import Event
|
||||||
import wave
|
import wave
|
||||||
@@ -38,6 +39,9 @@ class AudioTranscriber:
|
|||||||
self.transcription_engine = "Whisper"
|
self.transcription_engine = "Whisper"
|
||||||
|
|
||||||
def transcribeAudioQueue(self, audio_queue, language, country):
|
def transcribeAudioQueue(self, audio_queue, language, country):
|
||||||
|
if audio_queue.empty():
|
||||||
|
time.sleep(0.1)
|
||||||
|
return False
|
||||||
audio, time_spoken = audio_queue.get()
|
audio, time_spoken = audio_queue.get()
|
||||||
self.updateLastSampleAndPhraseStatus(audio, time_spoken)
|
self.updateLastSampleAndPhraseStatus(audio, time_spoken)
|
||||||
|
|
||||||
@@ -75,6 +79,7 @@ class AudioTranscriber:
|
|||||||
|
|
||||||
if text != '':
|
if text != '':
|
||||||
self.updateTranscript(text)
|
self.updateTranscript(text)
|
||||||
|
return True
|
||||||
|
|
||||||
def updateLastSampleAndPhraseStatus(self, data, time_spoken):
|
def updateLastSampleAndPhraseStatus(self, data, time_spoken):
|
||||||
source_info = self.audio_sources
|
source_info = self.audio_sources
|
||||||
|
|||||||
Reference in New Issue
Block a user