Spaces:
Paused
Paused
Commit ·
0e4f7a9
1
Parent(s): a4135ca
Auto-detect across all app languages with a small prior for English, Yoruba, Hausa
Browse files
src/models/asr_pipeline.py
CHANGED
|
@@ -80,7 +80,12 @@ class ASRPipeline:
|
|
| 80 |
# languages for every 30 s window, so Nigerian English, Pidgin or Yoruba
|
| 81 |
# could come back labelled (and transcribed) as an unrelated language.
|
| 82 |
# Whisper has no Igbo token; Igbo is chosen explicitly in the app.
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
def detect_language(self, audio: np.ndarray, sr: int = 16000) -> Optional[str]:
|
| 86 |
"""Most likely of AUTO_DETECT_LANGUAGES for the opening 30 s, or None."""
|
|
@@ -103,7 +108,7 @@ class ASRPipeline:
|
|
| 103 |
token_id = tokenizer.convert_tokens_to_ids(f"<|{code}|>")
|
| 104 |
if token_id is None or token_id == tokenizer.unk_token_id:
|
| 105 |
continue
|
| 106 |
-
score = logits[token_id].item()
|
| 107 |
if best_score is None or score > best_score:
|
| 108 |
best, best_score = code, score
|
| 109 |
return best
|
|
|
|
| 80 |
# languages for every 30 s window, so Nigerian English, Pidgin or Yoruba
|
| 81 |
# could come back labelled (and transcribed) as an unrelated language.
|
| 82 |
# Whisper has no Igbo token; Igbo is chosen explicitly in the app.
|
| 83 |
+
# These are the transcription languages the app offers.
|
| 84 |
+
AUTO_DETECT_LANGUAGES = ("en", "yo", "ha", "fr", "ar", "zh", "de", "hi", "id",
|
| 85 |
+
"ja", "ko", "ms", "pt", "ru", "es", "sw", "tr", "uk")
|
| 86 |
+
# Most users speak Nigerian English, Pidgin, Yoruba or Hausa. A small head
|
| 87 |
+
# start (log-prob units) stops accented speech being read as, say, Swahili.
|
| 88 |
+
LANGUAGE_PRIOR = {"en": 1.0, "yo": 1.0, "ha": 0.5}
|
| 89 |
|
| 90 |
def detect_language(self, audio: np.ndarray, sr: int = 16000) -> Optional[str]:
|
| 91 |
"""Most likely of AUTO_DETECT_LANGUAGES for the opening 30 s, or None."""
|
|
|
|
| 108 |
token_id = tokenizer.convert_tokens_to_ids(f"<|{code}|>")
|
| 109 |
if token_id is None or token_id == tokenizer.unk_token_id:
|
| 110 |
continue
|
| 111 |
+
score = logits[token_id].item() + self.LANGUAGE_PRIOR.get(code, 0.0)
|
| 112 |
if best_score is None or score > best_score:
|
| 113 |
best, best_score = code, score
|
| 114 |
return best
|