File size: 1,220 Bytes
1e38b6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from modules.whisper.whisper_factory import WhisperFactory
from modules.whisper.whisper_parameter import WhisperValues
from test_config import *

import pytest
import gradio as gr
import os


@pytest.mark.parametrize("whisper_type", ["whisper", "faster-whisper", "insanely_fast_whisper"])
def test_transcribe(whisper_type: str):
    audio_path = os.path.join("test.wav")
    if not os.path.exists(audio_path):
        download_file(TEST_FILE_DOWNLOAD_URL, audio_path)

    whisper_inferencer = WhisperFactory.create_whisper_inference(
        whisper_type=whisper_type,
    )

    print("Device : ", whisper_inferencer.device)

    hparams = WhisperValues(
        model_size=TEST_WHISPER_MODEL,
    ).as_list()

    whisper_inferencer.transcribe_file(
        files=[audio_path],
        progress=gr.Progress(),
        *hparams,
    )

    whisper_inferencer.transcribe_youtube(
        youtube_link=TEST_YOUTUBE_URL,
        progress=gr.Progress(),
        *hparams,
    )

    whisper_inferencer.transcribe_mic(
        mic_audio=audio_path,
        progress=gr.Progress(),
        *hparams,
    )


def download_file(url: str, path: str):
    if not os.path.exists(path):
        os.system(f"wget {url} -O {path}")