Fabrice-TIERCELIN commited on
Commit
22c3972
·
verified ·
1 Parent(s): 3001020

Fix output parameters

Browse files
Files changed (1) hide show
  1. app.py +50 -47
app.py CHANGED
@@ -29,58 +29,61 @@ tts = TTS(model_name, gpu=torch.cuda.is_available())
29
  tts.to(device_type)
30
 
31
  def predict(prompt, language, audio_file_pth, mic_file_path, use_mic):
32
- if True:
33
- if use_mic:
34
- if mic_file_path is None:
35
- gr.Warning("Please record your voice with Microphone, or uncheck Use Microphone to use reference audios")
36
- return (
37
- None,
38
- None,
39
- )
40
- else:
41
- speaker_wav = mic_file_path
42
  else:
43
- speaker_wav = audio_file_pth
 
 
44
 
45
- if len(prompt) < 2:
46
- gr.Warning("Please give a longer prompt text")
47
- return (
48
- None,
49
- None,
50
- )
51
- if len(prompt) > 50000:
52
- gr.Warning("Text length limited to 50000 characters for this demo, please try shorter text")
53
- return (
54
- None,
55
- None,
56
- )
57
- try:
58
- if language == "fr":
59
- if m.find("your") != -1:
60
- language = "fr-fr"
61
- if m.find("/fr/") != -1:
62
- language = None
63
- tts.tts_to_file(
64
- text=prompt,
65
- file_path="output.wav",
66
- speaker_wav=speaker_wav,
67
- language=language
68
  )
69
- except RuntimeError as e :
70
- if "device-assert" in str(e):
71
- # cannot do anything on cuda device side error, need to restart
72
- gr.Warning("Unhandled Exception encounter, please retry in a minute")
73
- print("Cuda device-assert Runtime encountered need restart")
74
- sys.exit("Exit due to cuda device-assert")
75
- else:
76
- raise e
77
-
78
  return (
79
- gr.make_waveform(
80
- audio="output.wav",
81
- ),
82
- "output.wav",
 
 
 
 
 
 
 
 
 
 
 
83
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  with gr.Blocks() as interface:
86
  gr.HTML("Multi-language Text-to-Speech")
 
29
  tts.to(device_type)
30
 
31
  def predict(prompt, language, audio_file_pth, mic_file_path, use_mic):
32
+ if use_mic:
33
+ if mic_file_path is None:
34
+ gr.Warning("Please record your voice with Microphone, or uncheck Use Microphone to use reference audios")
35
+ return (
36
+ None,
37
+ None,
38
+ None,
39
+ )
 
 
40
  else:
41
+ speaker_wav = mic_file_path
42
+ else:
43
+ speaker_wav = audio_file_pth
44
 
45
+ if len(prompt) < 2:
46
+ gr.Warning("Please give a longer prompt text")
47
+ return (
48
+ None,
49
+ None,
50
+ None,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  )
52
+ if len(prompt) > 50000:
53
+ gr.Warning("Text length limited to 50000 characters for this demo, please try shorter text")
 
 
 
 
 
 
 
54
  return (
55
+ None,
56
+ None,
57
+ None,
58
+ )
59
+ try:
60
+ if language == "fr":
61
+ if m.find("your") != -1:
62
+ language = "fr-fr"
63
+ if m.find("/fr/") != -1:
64
+ language = None
65
+ tts.tts_to_file(
66
+ text=prompt,
67
+ file_path="output.wav",
68
+ speaker_wav=speaker_wav,
69
+ language=language
70
  )
71
+ except RuntimeError as e :
72
+ if "device-assert" in str(e):
73
+ # cannot do anything on cuda device side error, need to restart
74
+ gr.Warning("Unhandled Exception encounter, please retry in a minute")
75
+ print("Cuda device-assert Runtime encountered need restart")
76
+ sys.exit("Exit due to cuda device-assert")
77
+ else:
78
+ raise e
79
+
80
+ return (
81
+ gr.make_waveform(
82
+ audio="output.wav",
83
+ ),
84
+ "output.wav",
85
+ None,
86
+ )
87
 
88
  with gr.Blocks() as interface:
89
  gr.HTML("Multi-language Text-to-Speech")