return both en and fr in transcriptio

This commit is contained in:
Gokul Mohanarangan
2023-08-28 14:25:44 +05:30
parent 3878c98357
commit 49d6e2d1dc
6 changed files with 45 additions and 26 deletions

View File

@@ -58,7 +58,10 @@ class AudioTranscriptModalProcessor(AudioTranscriptProcessor):
# Update code here once this is possible.
# i.e) extract from context/session objects
source_language = "en"
target_language = "en"
# TODO: target lang is set to "fr" for demo purposes
# Revert back once language selection is implemented
target_language = "fr"
languages = TranslationLanguages()
# Only way to set the target should be the UI element like dropdown.
@@ -74,7 +77,7 @@ class AudioTranscriptModalProcessor(AudioTranscriptProcessor):
files=files,
timeout=self.timeout,
headers=self.headers,
json=json_payload,
data=json_payload,
)
self.logger.debug(
@@ -84,12 +87,14 @@ class AudioTranscriptModalProcessor(AudioTranscriptProcessor):
result = response.json()
# Sanity check for translation status in the result
translation = ""
if target_language in result["text"]:
text = result["text"][target_language]
else:
text = result["text"][source_language]
translation = result["text"][target_language]
text = result["text"][source_language]
transcript = Transcript(
text=text,
translation=translation,
words=[
Word(
text=word["text"],

View File

@@ -34,12 +34,12 @@ class TranscriptLinerProcessor(Processor):
if "." not in word.text:
continue
partial.translation = self.transcript.translation
# emit line
await self.emit(partial)
# create new transcript
partial = Transcript(words=[])
self.transcript = partial
async def _flush(self):

View File

@@ -47,6 +47,7 @@ class Word(BaseModel):
class Transcript(BaseModel):
text: str = ""
translation: str = ""
words: list[Word] = None
@property
@@ -84,7 +85,7 @@ class Transcript(BaseModel):
words = [
Word(text=word.text, start=word.start, end=word.end) for word in self.words
]
return Transcript(text=self.text, words=words)
return Transcript(text=self.text, translation=self.translation, words=words)
class TitleSummary(BaseModel):