Spaces:
Zannriell
/
Build error

gorkemgoknar commited on
Commit
f89c55d
1 Parent(s): 6bef156

Use a language detector to minimize errors

Browse files

Language detector might be inaccurate for very short text (or mixed language), please clone this repository and modify if you need that feature.

Files changed (1) hide show
  1. app.py +36 -0
app.py CHANGED
@@ -3,6 +3,8 @@ import os
3
  # By using XTTS you agree to CPML license https://coqui.ai/cpml
4
  os.environ["COQUI_TOS_AGREED"] = "1"
5
 
 
 
6
  import gradio as gr
7
  from TTS.api import TTS
8
 
@@ -11,6 +13,35 @@ tts.to("cuda")
11
 
12
  def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree):
13
  if agree == True:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  if use_mic == True:
15
  if mic_file_path is not None:
16
  speaker_wav=mic_file_path
@@ -82,6 +113,11 @@ Leave a star on the Github <a href="https://github.com/coqui-ai/TTS">🐸TTS</a>
82
  <a href="https://huggingface.co/spaces/coqui/xtts?duplicate=true">
83
  <img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
84
  </p>
 
 
 
 
 
85
  """
86
 
87
  article = """
 
3
  # By using XTTS you agree to CPML license https://coqui.ai/cpml
4
  os.environ["COQUI_TOS_AGREED"] = "1"
5
 
6
+ import langid
7
+
8
  import gradio as gr
9
  from TTS.api import TTS
10
 
 
13
 
14
  def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree):
15
  if agree == True:
16
+ supported_languages=["en","es","fr","de","it","pt","pl","tr","ru","nl","cs","ar","zh-cn"]
17
+
18
+ if language not in supported_languages:
19
+ gr.Warning("Language you put in is not in is not in our Supported Languages, please choose from dropdown")
20
+
21
+ return (
22
+ None,
23
+ None,
24
+ )
25
+
26
+ language_predicted=langid.classify(prompt)[0].strip() # strip need as there is space at end!
27
+
28
+ if language_predicted == "zh":
29
+ #we use zh-cn
30
+ language_predicted = "zh-cn"
31
+ print(f"Detected language:{language_predicted}, Chosen language:{language}")
32
+
33
+ if language_predicted != language:
34
+ #Please duplicate and remove this check if you really want this
35
+ #Or auto-detector fails to identify language (which it can on pretty short text or mixed text)
36
+ gr.Warning(f"Auto-Predicted Language in prompt (detected: {language_predicted}) does not match language you chose (chosen: {language}) , please choose correct language id. If you think this is incorrect please duplicate this space and modify code.")
37
+
38
+ return (
39
+ None,
40
+ None,
41
+ )
42
+
43
+
44
+
45
  if use_mic == True:
46
  if mic_file_path is not None:
47
  speaker_wav=mic_file_path
 
113
  <a href="https://huggingface.co/spaces/coqui/xtts?duplicate=true">
114
  <img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
115
  </p>
116
+ <p>Language Selectors:
117
+ Arabic: ar, Brazilian Portuguese: pt , Chinese: zh-cn, Czech: cs,<br/>
118
+ Dutch: nl, English: en, French: fr, Italian: it, Polish: pl,<br/>
119
+ Russian: ru, Spanish: es, Turkish: tr <br/>
120
+ </p>
121
  """
122
 
123
  article = """