Push gladia translations as a TranscriptionFrame
This commit is contained in:
@@ -384,16 +384,31 @@ class GladiaSTTService(STTService):
|
|||||||
if content["type"] == "transcript":
|
if content["type"] == "transcript":
|
||||||
utterance = content["data"]["utterance"]
|
utterance = content["data"]["utterance"]
|
||||||
confidence = utterance.get("confidence", 0)
|
confidence = utterance.get("confidence", 0)
|
||||||
|
language = utterance["language"]
|
||||||
transcript = utterance["text"]
|
transcript = utterance["text"]
|
||||||
if confidence >= self._confidence:
|
if confidence >= self._confidence:
|
||||||
if content["data"]["is_final"]:
|
if content["data"]["is_final"]:
|
||||||
await self.push_frame(
|
await self.push_frame(
|
||||||
TranscriptionFrame(transcript, "", time_now_iso8601())
|
TranscriptionFrame(transcript, "", time_now_iso8601(), language)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await self.push_frame(
|
await self.push_frame(
|
||||||
InterimTranscriptionFrame(transcript, "", time_now_iso8601())
|
InterimTranscriptionFrame(
|
||||||
|
transcript, "", time_now_iso8601(), language
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
elif content["type"] == "translation":
|
||||||
|
translated_utterance = content["data"]["translated_utterance"]
|
||||||
|
original_language = content["data"]["original_language"]
|
||||||
|
translated_language = translated_utterance["language"]
|
||||||
|
confidence = translated_utterance.get("confidence", 0)
|
||||||
|
translation = translated_utterance["text"]
|
||||||
|
if translated_language != original_language and confidence >= self._confidence:
|
||||||
|
await self.push_frame(
|
||||||
|
TranscriptionFrame(
|
||||||
|
translation, "", time_now_iso8601(), translated_language
|
||||||
|
)
|
||||||
|
)
|
||||||
except websockets.exceptions.ConnectionClosed:
|
except websockets.exceptions.ConnectionClosed:
|
||||||
# Expected when closing the connection
|
# Expected when closing the connection
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user