Skip to content

Commit

Permalink
Multilingual support + alphabetic language list
Browse files Browse the repository at this point in the history
fixes #94
  • Loading branch information
kaixxx committed Jan 6, 2025
1 parent d7506bc commit 586000b
Showing 1 changed file with 82 additions and 16 deletions.
98 changes: 82 additions & 16 deletions noScribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,68 @@
</body>
</html>"""

languages = {
"Auto": "auto",
"Multilingual": "multilingual",
"Afrikaans": "af",
"Arabic": "ar",
"Armenian": "hy",
"Azerbaijani": "az",
"Belarusian": "be",
"Bosnian": "bs",
"Bulgarian": "bg",
"Catalan": "ca",
"Chinese": "zh",
"Croatian": "hr",
"Czech": "cs",
"Danish": "da",
"Dutch": "nl",
"English": "en",
"Estonian": "et",
"Finnish": "fi",
"French": "fr",
"Galician": "gl",
"German": "de",
"Greek": "el",
"Hebrew": "he",
"Hindi": "hi",
"Hungarian": "hu",
"Icelandic": "is",
"Indonesian": "id",
"Italian": "it",
"Japanese": "ja",
"Kannada": "kn",
"Kazakh": "kk",
"Korean": "ko",
"Latvian": "lv",
"Lithuanian": "lt",
"Macedonian": "mk",
"Malay": "ms",
"Marathi": "mr",
"Maori": "mi",
"Nepali": "ne",
"Norwegian": "no",
"Persian": "fa",
"Polish": "pl",
"Portuguese": "pt",
"Romanian": "ro",
"Russian": "ru",
"Serbian": "sr",
"Slovak": "sk",
"Slovenian": "sl",
"Spanish": "es",
"Swahili": "sw",
"Swedish": "sv",
"Tagalog": "tl",
"Tamil": "ta",
"Thai": "th",
"Turkish": "tr",
"Ukrainian": "uk",
"Urdu": "ur",
"Vietnamese": "vi",
"Welsh": "cy",
}

# config
config_dir = appdirs.user_config_dir('noScribe')
if not os.path.exists(config_dir):
Expand Down Expand Up @@ -453,11 +515,13 @@ def __init__(self):
self.label_language = ctk.CTkLabel(self.frame_options, text=t('label_language'))
self.label_language.grid(column=0, row=2, sticky='w', pady=5)

self.langs = ('auto', 'en (english)', 'zh (chinese)', 'de (german)', 'es (spanish)', 'ru (russian)', 'ko (korean)', 'fr (french)', 'ja (japanese)', 'pt (portuguese)', 'tr (turkish)', 'pl (polish)', 'ca (catalan)', 'nl (dutch)', 'ar (arabic)', 'sv (swedish)', 'it (italian)', 'id (indonesian)', 'hi (hindi)', 'fi (finnish)', 'vi (vietnamese)', 'he (hebrew)', 'uk (ukrainian)', 'el (greek)', 'ms (malay)', 'cs (czech)', 'ro (romanian)', 'da (danish)', 'hu (hungarian)', 'ta (tamil)', 'no (norwegian)', 'th (thai)', 'ur (urdu)', 'hr (croatian)', 'bg (bulgarian)', 'lt (lithuanian)', 'la (latin)', 'mi (maori)', 'ml (malayalam)', 'cy (welsh)', 'sk (slovak)', 'te (telugu)', 'fa (persian)', 'lv (latvian)', 'bn (bengali)', 'sr (serbian)', 'az (azerbaijani)', 'sl (slovenian)', 'kn (kannada)', 'et (estonian)', 'mk (macedonian)', 'br (breton)', 'eu (basque)', 'is (icelandic)', 'hy (armenian)', 'ne (nepali)', 'mn (mongolian)', 'bs (bosnian)', 'kk (kazakh)', 'sq (albanian)', 'sw (swahili)', 'gl (galician)', 'mr (marathi)', 'pa (punjabi)', 'si (sinhala)', 'km (khmer)', 'sn (shona)', 'yo (yoruba)', 'so (somali)', 'af (afrikaans)', 'oc (occitan)', 'ka (georgian)', 'be (belarusian)', 'tg (tajik)', 'sd (sindhi)', 'gu (gujarati)', 'am (amharic)', 'yi (yiddish)', 'lo (lao)', 'uz (uzbek)', 'fo (faroese)', 'ht (haitian creole)', 'ps (pashto)', 'tk (turkmen)', 'nn (nynorsk)', 'mt (maltese)', 'sa (sanskrit)', 'lb (luxembourgish)', 'my (myanmar)', 'bo (tibetan)', 'tl (tagalog)', 'mg (malagasy)', 'as (assamese)', 'tt (tatar)', 'haw (hawaiian)', 'ln (lingala)', 'ha (hausa)', 'ba (bashkir)', 'jw (javanese)', 'su (sundanese)')

self.option_menu_language = ctk.CTkOptionMenu(self.frame_options, width=100, values=self.langs, dynamic_resizing=False)
self.option_menu_language = ctk.CTkOptionMenu(self.frame_options, width=100, values=list(languages.keys()), dynamic_resizing=False)
self.option_menu_language.grid(column=1, row=2, sticky='e', pady=5)
self.option_menu_language.set(get_config('last_language', 'auto'))
last_language = get_config('last_language', 'auto')
if last_language in languages.keys():
self.option_menu_language.set(last_language)
else:
self.option_menu_language.set('auto')

# Whisper Model Selection
class CustomCTkOptionMenu(ctk.CTkOptionMenu):
Expand Down Expand Up @@ -887,11 +951,8 @@ def transcription_worker(self):

option_info += f'{t("label_whisper_model")} {sel_whisper_model} | '

self.language = self.option_menu_language.get()
if self.language != 'auto' and self.language != 'multilingual':
self.language = self.language[0:3].strip()

option_info += f'{t("label_language")} {self.language} | '
self.language_name = self.option_menu_language.get()
option_info += f'{t("label_language")} {self.language_name} ({languages[self.language_name]}) | '

self.speaker_detection = self.option_menu_speaker.get()
option_info += f'{t("label_speaker")} {self.speaker_detection} | '
Expand Down Expand Up @@ -1269,7 +1330,14 @@ def save_doc():
if self.cancel:
raise Exception(t('err_user_cancelation'))

whisper_lang = self.language if self.language != 'auto' else None
multilingual = False
if self.language_name == 'Multilingual':
multilingual = True
whisper_lang = None
elif self.language_name == 'Auto':
whisper_lang = None
else:
whisper_lang = languages[self.language_name]

# VAD

Expand Down Expand Up @@ -1325,7 +1393,7 @@ def adjust_for_pause(segment):
vad_parameters.speech_pad_ms = 400

# detect language
if self.language == 'auto':
if self.language_name == 'auto':
language, language_probability, all_language_probs = model.detect_language(
audio,
vad_filter=True,
Expand All @@ -1340,13 +1408,14 @@ def adjust_for_pause(segment):
prompts = yaml.safe_load(file)
except:
prompts = {}
self.prompt = prompts.get(self.language, '') # Fetch language prompt, default to empty string
self.prompt = prompts.get(languages[self.language_name], '') # Fetch language prompt, default to empty string
else:
self.prompt = ''

segments, info = model.transcribe(
audio,
language=whisper_lang,
language=whisper_lang,
multilingual=multilingual,
beam_size=5,
#temperature=self.whisper_temperature,
word_timestamps=True,
Expand All @@ -1357,9 +1426,6 @@ def adjust_for_pause(segment):
# length_penalty=0.5
)

#if self.language == "auto":
# self.logn("Detected language '%s' with probability %f" % (info.language, info.language_probability))

if self.cancel:
raise Exception(t('err_user_cancelation'))

Expand Down

0 comments on commit 586000b

Please sign in to comment.