jhj0517 commited on
Commit
1e38b6e
·
1 Parent(s): ffaa4d2

Add test script

Browse files
tests/test_config.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ TEST_FILE_DOWNLOAD_URL = "http://www.voiptroubleshooter.com/open_speech/american/OSR_us_000_0010_8k.wav"
4
+ TEST_YOUTUBE_URL = "https://www.youtube.com/watch?v=4WEQtgnBu0I&ab_channel=AndriaFitzer"
5
+ TEST_WHISPER_MODEL = "tiny"
6
+ TEST_UVR_MODEL = "UVR-MDX-NET-Inst_HQ_4"
7
+ TEST_NLLB_MODEL = "facebook/nllb-200-1.3B"
8
+ TEST_SUBTITLE_PATH = os.path.join("translation_test.srt")
9
+
tests/transcription.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from modules.whisper.whisper_factory import WhisperFactory
2
+ from modules.whisper.whisper_parameter import WhisperValues
3
+ from test_config import *
4
+
5
+ import pytest
6
+ import gradio as gr
7
+ import os
8
+
9
+
10
+ @pytest.mark.parametrize("whisper_type", ["whisper", "faster-whisper", "insanely_fast_whisper"])
11
+ def test_transcribe(whisper_type: str):
12
+ audio_path = os.path.join("test.wav")
13
+ if not os.path.exists(audio_path):
14
+ download_file(TEST_FILE_DOWNLOAD_URL, audio_path)
15
+
16
+ whisper_inferencer = WhisperFactory.create_whisper_inference(
17
+ whisper_type=whisper_type,
18
+ )
19
+
20
+ print("Device : ", whisper_inferencer.device)
21
+
22
+ hparams = WhisperValues(
23
+ model_size=TEST_WHISPER_MODEL,
24
+ ).as_list()
25
+
26
+ whisper_inferencer.transcribe_file(
27
+ files=[audio_path],
28
+ progress=gr.Progress(),
29
+ *hparams,
30
+ )
31
+
32
+ whisper_inferencer.transcribe_youtube(
33
+ youtube_link=TEST_YOUTUBE_URL,
34
+ progress=gr.Progress(),
35
+ *hparams,
36
+ )
37
+
38
+ whisper_inferencer.transcribe_mic(
39
+ mic_audio=audio_path,
40
+ progress=gr.Progress(),
41
+ *hparams,
42
+ )
43
+
44
+
45
+ def download_file(url: str, path: str):
46
+ if not os.path.exists(path):
47
+ os.system(f"wget {url} -O {path}")
tests/translation_test.srt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ 1
2
+ 00:00:00,000 --> 00:00:02,240
3
+ You've got
4
+
5
+ 2
6
+ 00:00:02,240 --> 00:00:04,160
7
+ a friend in me.