File size: 2,255 Bytes
c3e6538
 
 
 
 
 
 
 
 
 
 
 
f01c927
c3e6538
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f01c927
 
c3e6538
 
 
 
 
 
 
 
4817b42
 
f01c927
 
 
c3e6538
 
4817b42
 
c3e6538
 
 
 
 
 
 
 
 
4817b42
c3e6538
4817b42
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
64
65
66
67
68
import torch
#from transformers import pipeline
#from transformers.pipelines.audio_utils import ffmpeg_read
from speechscore import SpeechScore 
import gradio as gr

MODEL_NAME = "alibabasglab/speechscore"
BATCH_SIZE = 1

device = 0 if torch.cuda.is_available() else "cpu"

mySpeechScore = SpeechScore([
        'PESQ','DNSMOS'
    ])


# Copied from https://github.com/openai/whisper/blob/c09a7ae299c4c34c5839a76380ae407e7d785914/whisper/utils.py#L50
def format_timestamp(seconds: float, always_include_hours: bool = False, decimal_marker: str = "."):
    if seconds is not None:
        milliseconds = round(seconds * 1000.0)

        hours = milliseconds // 3_600_000
        milliseconds -= hours * 3_600_000

        minutes = milliseconds // 60_000
        milliseconds -= minutes * 60_000

        seconds = milliseconds // 1_000
        milliseconds -= seconds * 1_000

        hours_marker = f"{hours:02d}:" if always_include_hours or hours > 0 else ""
        return f"{hours_marker}{minutes:02d}:{seconds:02d}{decimal_marker}{milliseconds:03d}"
    else:
        # we have a malformed timestamp so just return it as is
        return seconds


def score(test_file, ref_file, dnsmos, pesq, return_timestamps):
    scores = mySpeechScore(test_path=test_file, reference_path=ref_file, dnsmos=dnsmos, pesq=pesq, window=None, score_rate=16000, return_mean=False)
    return scores


demo = gr.Blocks()

file_score = gr.Interface(
    fn=score,
    inputs=[
        gr.Audio(sources=["upload"], label="test file", type="filepath"),
        gr.Audio(sources=["upload"], label="reference file", type="filepath"),
        #gr.Radio(["without reference", "with reference"], label="Task", info="choose non-instrusive or instrusive scoring"),
        gr.Checkbox(default=False, label="DNSMOS"),
        gr.Checkbox(default=False, label="PESQ"),
    ],
    outputs="text",
    #layout="horizontal",
    #theme="huggingface",
    title="Score speech from a file",
    description=(
        "Score audio inputs with the click of a button! Demo uses the"
        " commonly used speech quality assessment methods for the audio files"
        " of arbitrary length."
    ),
)

with demo:
    gr.TabbedInterface([file_score], ["Score Audio File"])

demo.launch()