alessandro trinca tornidor commited on
Commit
6957865
1 Parent(s): ab57dda

feat: added text-to-speech in browser, updated e2e playwright test cases

Browse files
app.py CHANGED
@@ -10,6 +10,46 @@ css = """
10
  .speech-output-container {align-items: center; min-height: 60px; padding-left: 8px; padding-right: 8px; margin-top: -12px; border-width: 1px; border-style: solid; border-color: lightgrey;}
11
  """
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  def clear():
15
  return None
@@ -53,12 +93,12 @@ with gr.Blocks(css=css) as gradio_app:
53
  value="Hi there, how are you?",
54
  )
55
  with gr.Row():
56
- with gr.Column(scale=7, min_width=240):
57
- audio_tts = gr.Audio(label="Audio TTS")
58
- with gr.Column(scale=1, min_width=50):
59
- btn_run_tts = gr.Button(value="Run TTS")
60
- btn_clear_tts = gr.Button(value="Clear TTS")
61
- btn_clear_tts.click(clear, inputs=[], outputs=[audio_tts])
62
  with gr.Row():
63
  audio_learner_recording_stt = gr.Audio(
64
  label="Learner Recording",
@@ -156,7 +196,8 @@ with gr.Blocks(css=css) as gradio_app:
156
  number_score_de, number_score_en
157
  ],
158
  )
159
- btn_run_tts.click(
 
160
  fn=lambdaTTS.get_tts,
161
  inputs=[text_learner_transcription, radio_language],
162
  outputs=audio_tts,
 
10
  .speech-output-container {align-items: center; min-height: 60px; padding-left: 8px; padding-right: 8px; margin-top: -12px; border-width: 1px; border-style: solid; border-color: lightgrey;}
11
  """
12
 
13
+ js_play_audio = """
14
+ function playAudio(text, language) {
15
+ let voice_idx = 0;
16
+ let voice_synth = null;
17
+ let synth = window.speechSynthesis;
18
+
19
+ function setSpeech() {
20
+ return new Promise(
21
+ function (resolve, reject) {
22
+ let id;
23
+
24
+ id = setInterval(() => {
25
+ if (synth.getVoices().length !== 0) {
26
+ resolve(synth.getVoices());
27
+ clearInterval(id);
28
+ }
29
+ }, 10);
30
+ }
31
+ )
32
+ }
33
+
34
+ let s = setSpeech();
35
+ s.then((voices) => {
36
+ for (idx = 0; idx < voices.length; idx++) {
37
+ if (voices[idx].lang.slice(0, 2) == language) {
38
+ voice_synth = voices[idx];
39
+ break;
40
+ }
41
+ }
42
+
43
+ var utterThis = new SpeechSynthesisUtterance(text);
44
+ utterThis.voice = voice_synth;
45
+ utterThis.rate = 0.7;
46
+
47
+ synth.speak(utterThis);
48
+ return utterThis;
49
+ });
50
+ }
51
+ """
52
+
53
 
54
  def clear():
55
  return None
 
93
  value="Hi there, how are you?",
94
  )
95
  with gr.Row():
96
+ audio_tts = gr.Audio(label="Audio TTS")
97
+ with gr.Row():
98
+ btn_run_tts = gr.Button(value="TTS in browser")
99
+ btn_run_tts_backend = gr.Button(value="TTS backend")
100
+ btn_clear_tts = gr.Button(value="Clear TTS backend")
101
+ btn_clear_tts.click(clear, inputs=[], outputs=[audio_tts])
102
  with gr.Row():
103
  audio_learner_recording_stt = gr.Audio(
104
  label="Learner Recording",
 
196
  number_score_de, number_score_en
197
  ],
198
  )
199
+ btn_run_tts.click(fn=None, inputs=[text_learner_transcription, radio_language], outputs=audio_tts, js=js_play_audio)
200
+ btn_run_tts_backend.click(
201
  fn=lambdaTTS.get_tts,
202
  inputs=[text_learner_transcription, radio_language],
203
  outputs=audio_tts,
static/tests/test-app-7860-example-medium0-upload-de.spec.ts CHANGED
@@ -21,8 +21,8 @@ test("test: get a phonetic accuracy evaluation from an uploaded audio file.", as
21
  accordionExamples.click();
22
  const exampleMediumFirst = page.getByRole('gridcell', { name: 'medium' }).first();
23
  await exampleMediumFirst.click();
24
-
25
- await page.getByRole('button', { name: 'Run TTS' }).click();
26
  const buttonPlay = page.getByLabel('Play', { exact: true })
27
  await buttonPlay.click();
28
  const waveFormTTS = page.locator('.scroll > .wrapper').first();
 
21
  accordionExamples.click();
22
  const exampleMediumFirst = page.getByRole('gridcell', { name: 'medium' }).first();
23
  await exampleMediumFirst.click();
24
+
25
+ await page.getByRole('button', { name: 'TTS backend', exact: true }).click();
26
  const buttonPlay = page.getByLabel('Play', { exact: true })
27
  await buttonPlay.click();
28
  const waveFormTTS = page.locator('.scroll > .wrapper').first();
static/tests/test-app-7860-example-medium0-upload-en.spec.ts CHANGED
@@ -22,7 +22,7 @@ test("test: get a phonetic accuracy evaluation from an uploaded audio file.", as
22
  const exampleMediumFirst = page.getByRole('gridcell', { name: 'medium' }).nth(1);
23
  await exampleMediumFirst.click();
24
 
25
- await page.getByRole('button', { name: 'Run TTS' }).click();
26
  const buttonPlay = page.getByLabel('Play', { exact: true })
27
  await buttonPlay.click();
28
  const waveFormTTS = page.locator('.scroll > .wrapper').first();
 
22
  const exampleMediumFirst = page.getByRole('gridcell', { name: 'medium' }).nth(1);
23
  await exampleMediumFirst.click();
24
 
25
+ await page.getByRole('button', { name: 'TTS backend', exact: true }).click();
26
  const buttonPlay = page.getByLabel('Play', { exact: true })
27
  await buttonPlay.click();
28
  const waveFormTTS = page.locator('.scroll > .wrapper').first();
static/tests/test-app-7860-random-upload-de.spec.ts CHANGED
@@ -34,7 +34,7 @@ test("test: get a phonetic accuracy evaluation from an uploaded audio file.", as
34
  learnerTranscriptionScreenshot1.toString('base64')
35
  )
36
 
37
- await page.getByRole('button', { name: 'Run TTS' }).click();
38
  const buttonPlay = page.getByLabel('Play', { exact: true })
39
  await buttonPlay.click();
40
  const waveFormTTS = page.locator('.scroll > .wrapper').first();
 
34
  learnerTranscriptionScreenshot1.toString('base64')
35
  )
36
 
37
+ await page.getByRole('button', { name: 'TTS backend', exact: true }).click();
38
  const buttonPlay = page.getByLabel('Play', { exact: true })
39
  await buttonPlay.click();
40
  const waveFormTTS = page.locator('.scroll > .wrapper').first();
static/tests/test-app-7860-random-upload-en.spec.ts CHANGED
@@ -34,7 +34,7 @@ test("test: get a phonetic accuracy evaluation from an uploaded audio file.", as
34
  learnerTranscriptionScreenshot1.toString('base64')
35
  )
36
 
37
- await page.getByRole('button', { name: 'Run TTS' }).click();
38
  const buttonPlay = page.getByLabel('Play', { exact: true })
39
  await buttonPlay.click();
40
  const waveFormTTS = page.locator('.scroll > .wrapper').first();
 
34
  learnerTranscriptionScreenshot1.toString('base64')
35
  )
36
 
37
+ await page.getByRole('button', { name: 'TTS backend', exact: true }).click();
38
  const buttonPlay = page.getByLabel('Play', { exact: true })
39
  await buttonPlay.click();
40
  const waveFormTTS = page.locator('.scroll > .wrapper').first();
static/tests/test-app-7860-upload-de.spec.ts CHANGED
@@ -23,7 +23,7 @@ test("test: get a phonetic accuracy evaluation from an uploaded audio file.", as
23
  const textboxLearnerTranscriptionInput = page.getByLabel('Learner Transcription')
24
  await textboxLearnerTranscriptionInput.fill('Ich bin Alex, wer bist du?');
25
 
26
- await page.getByRole('button', { name: 'Run TTS' }).click();
27
  const buttonPlay = page.getByLabel('Play', { exact: true })
28
  await buttonPlay.click();
29
  const waveFormTTS = page.locator('.scroll > .wrapper').first();
 
23
  const textboxLearnerTranscriptionInput = page.getByLabel('Learner Transcription')
24
  await textboxLearnerTranscriptionInput.fill('Ich bin Alex, wer bist du?');
25
 
26
+ await page.getByRole('button', { name: 'TTS backend', exact: true }).click();
27
  const buttonPlay = page.getByLabel('Play', { exact: true })
28
  await buttonPlay.click();
29
  const waveFormTTS = page.locator('.scroll > .wrapper').first();
static/tests/test-app-7860-upload-en.spec.ts CHANGED
@@ -16,7 +16,7 @@ test("test: get a phonetic accuracy evaluation from an uploaded audio file.", as
16
  const page = await browser.newPage({});
17
 
18
  await page.goto('http://localhost:7860/');
19
- await page.getByRole('button', { name: 'Run TTS' }).click();
20
  const buttonPlay = page.getByLabel('Play', { exact: true })
21
  await buttonPlay.click();
22
  const waveFormTTS = page.locator('.scroll > .wrapper').first();
 
16
  const page = await browser.newPage({});
17
 
18
  await page.goto('http://localhost:7860/');
19
+ await page.getByRole('button', { name: 'TTS backend', exact: true }).click();
20
  const buttonPlay = page.getByLabel('Play', { exact: true })
21
  await buttonPlay.click();
22
  const waveFormTTS = page.locator('.scroll > .wrapper').first();