auto detect language ppython client

This commit is contained in:
makaveli10
2023-07-28 15:34:50 +08:00
parent ecfc2b2c88
commit eddd615a9d
2 changed files with 26 additions and 6 deletions
+18
View File
@@ -140,6 +140,24 @@ class ServeClient:
"""
Process audio stream in an infinite loop.
"""
# detect language
if self.language is None:
# wait for 30s of audio
while self.frames_np is None or self.frames_np.shape[0] < 30*self.RATE:
time.sleep(1)
input_bytes = self.frames_np[-30*self.RATE:].copy()
self.frames_np = None
duration = input_bytes.shape[0] / self.RATE
self.language, lang_prob = self.transcriber.transcribe(
input_bytes,
initial_prompt=None,
language=self.language,
task=self.task
)
logging.info(f"Detected language {self.language} with probability {lang_prob}")
self.websocket.send(json.dumps({"language": self.language, "language_prob": lang_prob}))
while True:
if self.exit:
logging.info("Exiting speech to text thread")