thewh1teagle commited on
Commit
787fd4f
โ€ข
1 Parent(s): 9cd4361
Files changed (2) hide show
  1. app.py +20 -15
  2. requirements.txt +2 -2
app.py CHANGED
@@ -10,16 +10,17 @@ python3 app.py
10
 
11
  import gradio as gr
12
  from israwave import IsraWave
13
- from israwave.helpers import text_has_niqqud
14
  from nakdimon_ort import Nakdimon
15
  from israwave.segment import SegmentExtractor
16
  import numpy as np
17
 
18
  segment_extractor = SegmentExtractor()
19
- speech_model = IsraWave('israwave.onnx', 'espeak-ng-data')
20
- niqqud_model = Nakdimon('nakdimon.onnx')
21
 
22
- def create_audio(text: str, rate, pitch, energy):
 
23
  if not text_has_niqqud(text):
24
  text = niqqud_model.compute(text)
25
  waveforms = []
@@ -28,11 +29,10 @@ def create_audio(text: str, rate, pitch, energy):
28
  waveforms.append(waveform.samples)
29
  silence = segment.create_pause(waveform.sample_rate)
30
  waveforms.append(silence)
31
- return np.concatenate(waveforms), speech_model.sample_rate
32
-
33
- def create(text, rate, pitch, energy):
34
- samples, sample_rate = create_audio(text, rate, pitch, energy)
35
- return (sample_rate, samples)
36
 
37
 
38
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
@@ -41,16 +41,21 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
41
  <h1 style='text-align: center;'>IsraWave</h1>
42
  <p style='text-align: center;'>Text-to-Speech model for Hebrew</p>
43
  """)
44
-
45
  # Use Textarea with RTL direction
46
- text = gr.TextArea(label="text", lines=4, elem_id="rtl_textarea", value='ื–ื” ื›ื™ืฃ ืœื”ื–ืžื™ืŸ ื“ื‘ืจื™ื ื‘ืื™ื ื˜ืจื ื˜, ืื‘ืœ ื”ืจื‘ื” ืคื—ื•ืช ื›ื™ืฃ ืœื—ื›ื•ืช ื•ืœื—ื›ื•ืช ืขื“ ืฉื”ื ื™ื’ื™ืขื• ืืœื™ื ื•. ืื– ืžื” ื‘ืขืฆื ืขื•ื‘ืจ ืขืœ ื”ื—ื‘ื™ืœื•ืช ื‘ื“ืจืš ื”ืืจื•ื›ื” ืขื“ ืœื‘ื™ืช ืฉืœื ื•? ื•ื”ืื ืืคืฉืจ ืœื’ืจื•ื ืœื›ืš ืฉื”ืŸ ื™ื’ื™ืขื• ืžื”ืจ ื™ื•ืชืจ? ')
 
 
 
 
 
47
  rate = gr.Slider(0.1, 10, label="rate", value=1.0)
48
  pitch = gr.Slider(0.1, 10, label="pitch", value=1.0)
49
  energy = gr.Slider(0.1, 10, label="energy", value=1.0)
50
 
51
- button = gr.Button("Create", elem_id="create_button")
52
  output = gr.Audio()
53
-
54
  button.click(fn=create, inputs=[text, rate, pitch, energy], outputs=output)
55
 
56
  # Custom CSS for RTL direction
@@ -60,9 +65,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
60
  font-size: 20px;
61
  }
62
  """
63
-
64
  gr.Markdown("""
65
  <p style='text-align: center;'><a href='https://github.com/thewh1teagle/israwave' target='_blank'>Israwave on Github</a></p>
66
  """)
67
 
68
- demo.launch()
 
10
 
11
  import gradio as gr
12
  from israwave import IsraWave
13
+ from israwave.helpers import text_has_niqqud, float_to_int16
14
  from nakdimon_ort import Nakdimon
15
  from israwave.segment import SegmentExtractor
16
  import numpy as np
17
 
18
  segment_extractor = SegmentExtractor()
19
+ speech_model = IsraWave("israwave.onnx", "espeak-ng-data")
20
+ niqqud_model = Nakdimon("nakdimon.onnx")
21
 
22
+
23
+ def create(text: str, rate, pitch, energy):
24
  if not text_has_niqqud(text):
25
  text = niqqud_model.compute(text)
26
  waveforms = []
 
29
  waveforms.append(waveform.samples)
30
  silence = segment.create_pause(waveform.sample_rate)
31
  waveforms.append(silence)
32
+ waveform = np.concatenate(waveforms)
33
+ # Gradio expect int16
34
+ waveform = float_to_int16(waveform)
35
+ return speech_model.sample_rate, waveform
 
36
 
37
 
38
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
 
41
  <h1 style='text-align: center;'>IsraWave</h1>
42
  <p style='text-align: center;'>Text-to-Speech model for Hebrew</p>
43
  """)
44
+
45
  # Use Textarea with RTL direction
46
+ text = gr.TextArea(
47
+ label="text",
48
+ lines=4,
49
+ elem_id="rtl_textarea",
50
+ value="ื–ื” ื›ื™ืฃ ืœื”ื–ืžื™ืŸ ื“ื‘ืจื™ื ื‘ืื™ื ื˜ืจื ื˜, ืื‘ืœ ื”ืจื‘ื” ืคื—ื•ืช ื›ื™ืฃ ืœื—ื›ื•ืช ื•ืœื—ื›ื•ืช ืขื“ ืฉื”ื ื™ื’ื™ืขื• ืืœื™ื ื•. ืื– ืžื” ื‘ืขืฆื ืขื•ื‘ืจ ืขืœ ื”ื—ื‘ื™ืœื•ืช ื‘ื“ืจืš ื”ืืจื•ื›ื” ืขื“ ืœื‘ื™ืช ืฉืœื ื•? ื•ื”ืื ืืคืฉืจ ืœื’ืจื•ื ืœื›ืš ืฉื”ืŸ ื™ื’ื™ืขื• ืžื”ืจ ื™ื•ืชืจ? ",
51
+ )
52
  rate = gr.Slider(0.1, 10, label="rate", value=1.0)
53
  pitch = gr.Slider(0.1, 10, label="pitch", value=1.0)
54
  energy = gr.Slider(0.1, 10, label="energy", value=1.0)
55
 
56
+ button = gr.Button("Create")
57
  output = gr.Audio()
58
+
59
  button.click(fn=create, inputs=[text, rate, pitch, energy], outputs=output)
60
 
61
  # Custom CSS for RTL direction
 
65
  font-size: 20px;
66
  }
67
  """
68
+
69
  gr.Markdown("""
70
  <p style='text-align: center;'><a href='https://github.com/thewh1teagle/israwave' target='_blank'>Israwave on Github</a></p>
71
  """)
72
 
73
+ demo.launch()
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- gradio
2
- israwave
 
1
+ gradio==4.44.0
2
+ israwave==0.1.5