update transcription
add daemon=True
This commit is contained in:
18
VRCT.py
18
VRCT.py
@@ -1,9 +1,9 @@
|
||||
import os
|
||||
import json
|
||||
import queue
|
||||
import time
|
||||
import customtkinter
|
||||
from PIL import Image
|
||||
import pyaudiowpatch as pyaudio
|
||||
|
||||
import utils
|
||||
import translation
|
||||
@@ -305,7 +305,8 @@ class App(customtkinter.CTk):
|
||||
## set transcription instance
|
||||
self.mic_queue = queue.Queue()
|
||||
self.spk_queue = queue.Queue()
|
||||
self.vr = transcription.VoiceRecognizer(self.mic_queue, self.spk_queue)
|
||||
self.p = pyaudio.PyAudio()
|
||||
self.vr = transcription.VoiceRecognizer(self.p, self.mic_queue, self.spk_queue)
|
||||
self.CHOICE_MIC_DEVICE = self.CHOICE_MIC_DEVICE if self.CHOICE_MIC_DEVICE is not None else self.vr.search_default_device()[0]
|
||||
self.CHOICE_SPEAKER_DEVICE = self.CHOICE_SPEAKER_DEVICE if self.CHOICE_SPEAKER_DEVICE is not None else self.vr.search_default_device()[1]
|
||||
|
||||
@@ -541,20 +542,9 @@ class App(customtkinter.CTk):
|
||||
self.attributes("-topmost", True)
|
||||
|
||||
def delete_window(self):
|
||||
if isinstance(self.th_vr_listen_mic, utils.thread_fnc):
|
||||
while not self.th_vr_listen_mic.stopped():
|
||||
self.th_vr_listen_mic.stop()
|
||||
if isinstance(self.th_vr_recognize_mic, utils.thread_fnc):
|
||||
while not self.th_vr_recognize_mic.stopped():
|
||||
self.th_vr_recognize_mic.stop()
|
||||
if self.vr.spk_stream is not None:
|
||||
self.vr.close_spk_stream()
|
||||
if isinstance(self.th_vr_recognize_spk, utils.thread_fnc):
|
||||
while not self.th_vr_recognize_spk.stopped():
|
||||
self.th_vr_recognize_spk.stop()
|
||||
self.quit()
|
||||
self.destroy()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
app = App()
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
import io
|
||||
import queue
|
||||
import numpy as np
|
||||
import soundcard as sc
|
||||
import soundfile as sf
|
||||
import sounddevice as sd
|
||||
import speech_recognition as sr
|
||||
import pyaudiowpatch as pyaudio
|
||||
|
||||
# VoiceRecognizer
|
||||
class VoiceRecognizer():
|
||||
def __init__(self, mic_queue, spk_queue):
|
||||
def __init__(self, p_audio, mic_queue, spk_queue):
|
||||
self.r = sr.Recognizer()
|
||||
self.p = pyaudio.PyAudio()
|
||||
self.p = p_audio
|
||||
|
||||
self.languages = [
|
||||
"ja-JP","en-US","en-GB","af-ZA","ar-DZ","ar-BH","ar-EG","ar-IL","ar-IQ","ar-JO","ar-KW","ar-LB","ar-MA",
|
||||
@@ -138,6 +133,7 @@ class VoiceRecognizer():
|
||||
return text
|
||||
|
||||
if __name__ == "__main__":
|
||||
import queue
|
||||
import threading
|
||||
|
||||
mic_queue = queue.Queue()
|
||||
|
||||
4
utils.py
4
utils.py
@@ -26,8 +26,8 @@ def print_textbox(textbox, message, tags=None):
|
||||
textbox.see("end")
|
||||
|
||||
class thread_fnc(threading.Thread):
|
||||
def __init__(self, fnc, *args, **kwargs):
|
||||
super(thread_fnc, self).__init__(*args, **kwargs)
|
||||
def __init__(self, fnc, daemon=True, *args, **kwargs):
|
||||
super(thread_fnc, self).__init__(daemon=daemon, *args, **kwargs)
|
||||
self.fnc = fnc
|
||||
self._stop = threading.Event()
|
||||
def stop(self):
|
||||
|
||||
Reference in New Issue
Block a user