File size: 2,800 Bytes
ab57dda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
03112f1
 
ab57dda
6957865
ab57dda
 
 
 
 
 
 
 
 
 
 
 
 
cb7eead
ab57dda
 
 
 
 
 
0e70ac7
 
 
 
 
 
 
 
 
 
 
 
 
ab57dda
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { test, expect, chromium } from "@playwright/test";

test("test: get a phonetic accuracy evaluation from an uploaded audio file.", async () => {
  const testAudioEnvPath = `${import.meta.dirname}/../../tests/events/test_de_easy.wav`
  console.log(`testAudioEnvPath: ${testAudioEnvPath}...`);
  
  const browser = await chromium.launch({
    args: [
        "--use-fake-device-for-media-stream",
      ],
      ignoreDefaultArgs: ['--mute-audio']
    })

  const context = await browser.newContext();
  context.grantPermissions(["microphone"]);
  const page = await browser.newPage({});

  await page.goto('http://localhost:7860/');

  const radioLanguageSelectedDE = page.getByRole('radio', { name: 'de' })
  await radioLanguageSelectedDE.check();

  const textboxStudentTranscriptionInput = page.getByLabel('Phrase to read for speech recognition')
  await textboxStudentTranscriptionInput.fill('Ich bin Alex, wer bist du?');

  await page.getByRole('button', { name: 'TTS backend', exact: true }).click();
  const buttonPlay = page.getByLabel('Play', { exact: true })
  await buttonPlay.click();
  const waveFormTTS = page.locator('.scroll > .wrapper').first();
  await waveFormTTS.waitFor({ state: 'attached' });
  await waveFormTTS.waitFor({ state: 'visible' });
  await expect(waveFormTTS).toBeVisible();

  const fileChooserPromise = page.waitForEvent('filechooser');
  await page.getByLabel('Upload file').click();
  await page.getByRole('button', { name: 'Drop Audio Here - or - Click' }).click();
  const fileChooser = await fileChooserPromise;
  await fileChooser.setFiles(testAudioEnvPath);
  
  await page.getByRole('button', { name: 'Get speech accuracy score (%)' }).click();

  await page.waitForTimeout(300);
  const errorsElements = page.getByText(/Error/);
  const ErrorText = errorsElements.all()
  console.log("ErrorText:", (await ErrorText).length, "#");
  await expect(errorsElements).toHaveCount(0);

  const currentWordIndex = page.getByLabel(/Current word index/);
  currentWordIndex.fill('1');
  const audioSlittedStudentSpeechOutput = page.getByTestId('waveform-Splitted student speech output');
  await expect(audioSlittedStudentSpeechOutput).toBeVisible();
  const buttonPlayStudentSpeechOutput = audioSlittedStudentSpeechOutput.getByLabel('Play', { exact: true })
  // before playing the audio, the color of the button should be gray
  await expect(buttonPlayStudentSpeechOutput).toHaveCSS('color', 'rgb(187, 187, 194)');
  await buttonPlayStudentSpeechOutput.click();
  await page.waitForTimeout(10);
  // after playing the audio, the color of the button should be orange, but only for few milliseconds: don't wait too long!
  await expect(buttonPlayStudentSpeechOutput).toHaveCSS('color', 'rgb(249, 115, 22)');
  
  console.log("end");
  await page.close();
});