Martijn Bartelds commited on
Commit
46ebc44
·
1 Parent(s): 7ca2569

Update app

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -17,19 +17,26 @@ gos_text2speech = Text2Speech.from_pretrained(
17
  noise_scale_dur=1.0
18
  )
19
 
20
- def inference(text,lang):
21
- with torch.no_grad():
22
- if lang == "Hoogelaandsters":
23
- wav = gos_text2speech(text.lower(), sids=np.array([1]))["wav"]
24
- sf.write("out.wav", wav.view(-1).cpu().numpy(), gos_text2speech.fs)
25
- if lang == "Oldambsters":
26
- wav = gos_text2speech(text.lower(), sids=np.array([2]))["wav"]
27
- sf.write("out.wav", wav.view(-1).cpu().numpy(), gos_text2speech.fs)
28
- if lang == "Westerkertaaiers":
29
- wav = gos_text2speech(text.lower(), sids=np.array([3]))["wav"]
30
- sf.write("out.wav", wav.view(-1).cpu().numpy(), gos_text2speech.fs)
31
-
32
- return "out.wav", "out.wav"
 
 
 
 
 
 
 
33
 
34
  title = "Gronings text-to-speech"
35
  examples = [
@@ -39,7 +46,7 @@ examples = [
39
  gr.Interface(
40
  inference,
41
  [gr.inputs.Textbox(label="Input text", lines=3), gr.inputs.Radio(choices=["Hoogelaandsters", "Oldambsters", "Westerkertaaiers"], type="value", default="Hoogelaandsters", label="Variant")],
42
- [gr.outputs.Audio(type="file", label="Output"), gr.outputs.File()],
43
  title=title,
44
  examples=examples
45
  ).launch(enable_queue=True)
 
17
  noise_scale_dur=1.0
18
  )
19
 
20
+ def inference(text, lang):
21
+ with torch.no_grad():
22
+ lines = text.splitlines()
23
+ outputs = []
24
+
25
+ for line in lines:
26
+ line = line.lower()
27
+ if lang == "Hoogelaandsters":
28
+ wav = gos_text2speech(line, sids=np.array([1]))["wav"]
29
+ elif lang == "Oldambsters":
30
+ wav = gos_text2speech(line, sids=np.array([2]))["wav"]
31
+ elif lang == "Westerkertaaiers":
32
+ wav = gos_text2speech(line, sids=np.array([3]))["wav"]
33
+
34
+ outputs.append(wav)
35
+
36
+ concatenated_wav = np.concatenate([o.view(-1).cpu().numpy() for o in outputs])
37
+ sf.write("out.wav", concatenated_wav, gos_text2speech.fs)
38
+
39
+ return "out.wav", "out.wav"
40
 
41
  title = "Gronings text-to-speech"
42
  examples = [
 
46
  gr.Interface(
47
  inference,
48
  [gr.inputs.Textbox(label="Input text", lines=3), gr.inputs.Radio(choices=["Hoogelaandsters", "Oldambsters", "Westerkertaaiers"], type="value", default="Hoogelaandsters", label="Variant")],
49
+ [gr.outputs.Audio(type="filepath", label="Output"), gr.outputs.File()],
50
  title=title,
51
  examples=examples
52
  ).launch(enable_queue=True)