Skip to content

Commit

Permalink
add multilingual support for deepgram
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekuppal committed Jun 18, 2024
1 parent d022c40 commit 7c95bd1
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions sdk/transcriber_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ def __init__(self, stt_model_config: dict):

# This parameter exists primarily to adhere to the interface.
# Deepgram does auto language detection.
self.lang = 'en-US'
# self.lang = 'en-US'
self.lang = stt_model_config['audio_lang']

print('[INFO] Using Deepgram API for transcription.')
self.audio_model = DeepgramClient(stt_model_config["api_key"])
Expand Down Expand Up @@ -406,18 +407,29 @@ def get_sentences(self, wav_file_path: str):
payload: FileSource = {
"buffer": buffer_data
}

options = PrerecordedOptions(
model="nova",
smart_format=True,
utterances=True,
punctuate=True,
paragraphs=True,
detect_language=True)
if self.lang.startswith('en'):
options = PrerecordedOptions(
model="nova",
smart_format=True,
utterances=True,
punctuate=True,
paragraphs=True,
detect_language=True,
language=self.lang)
else:
options = PrerecordedOptions(
model="general",
smart_format=True,
utterances=True,
punctuate=True,
paragraphs=True,
detect_language=True,
language=self.lang)

response = self.audio_model.listen.prerecorded.v("1").transcribe_file(payload, options)
# This is not necessary and just a debugging aid
with open('logs/deep.json', mode='a', encoding='utf-8') as deep_log:
log_file = f"{utilities.get_data_path(app_name='Transcribe')}/logs/deep.json"
with open(log_file, mode='a', encoding='utf-8') as deep_log:
deep_log.write(response.to_json(indent=4))
results = []
for utterance in response.results.utterances:
Expand Down

0 comments on commit 7c95bd1

Please sign in to comment.