Spaces:
Build error
Build error
File size: 8,674 Bytes
1ead8e8 f5460b4 1ead8e8 f5460b4 1ead8e8 f5460b4 1ead8e8 f5460b4 1ead8e8 f5460b4 1ead8e8 f5460b4 1ead8e8 f5460b4 1ead8e8 f5460b4 1ead8e8 |
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
"""
TODO:
+ [x] Load Configuration
+ [ ] Checking
+ [ ] Better saving directory
"""
import numpy as np
from pathlib import Path
import jiwer
import pdb
import torch.nn as nn
import torch
import torchaudio
from transformers import pipeline
from time import process_time, time
from pathlib import Path
# local import
import sys
from espnet2.bin.tts_inference import Text2Speech
# pdb.set_trace()
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
sys.path.append("src")
import gradio as gr
# ASR part
audio_files = [
str(x)
for x in sorted(
Path(
"/home/kevingeng/Disk2/laronix/laronix_automos/data/20230103_video"
).glob("**/*wav")
)
]
# audio_files = [str(x) for x in sorted(Path("./data/Patient_sil_trim_16k_normed_5_snr_40/Rainbow").glob("**/*wav"))]
transcriber = pipeline(
"automatic-speech-recognition",
model="KevinGeng/PAL_John_128_train_dev_test_seed_1",
)
old_transcriber = pipeline(
"automatic-speech-recognition", "facebook/wav2vec2-base-960h"
)
whisper_transcriber = pipeline(
"automatic-speech-recognition", "KevinGeng/whipser_medium_en_PAL300_step25"
)
whisper_transcriber_org = pipeline(
"automatic-speech-recognition", "KevinGeng/whisper-medium-PAL128-25step"
)
whisper_transcriber_Tony = pipeline(
"automatic-speech-recognition", "KevinGeng/Tony1_AVA_script_conv_train_conv_dev"
)
whisper_transcriber_John = pipeline(
"automatic-speech-recognition", "KevinGeng/whipser_medium_en_PAL300_step25_step2_VTCK"
)
whisper_transcriber_Negel = pipeline(
"automatic-speech-recognition", "KevinGeng/Negel_152_AVA_script_conv_train_conv_dev"
)
# transcriber = pipeline("automatic-speech-recognition", model="KevinGeng/PAL_John_128_p326_300_train_dev_test_seed_1")
# 【Female】kan-bayashi ljspeech parallel wavegan
# tts_model = Text2Speech.from_pretrained("espnet/kan-bayashi_ljspeech_vits")
# 【Male】fastspeech2-en-200_speaker-cv4, hifigan vocoder
# pdb.set_trace()
from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
# @title English multi-speaker pretrained model { run: "auto" }
lang = "English"
tag = "kan-bayashi/libritts_xvector_vits"
# vits needs no
vocoder_tag = "parallel_wavegan/vctk_parallel_wavegan.v1.long" # @param ["none", "parallel_wavegan/vctk_parallel_wavegan.v1.long", "parallel_wavegan/vctk_multi_band_melgan.v2", "parallel_wavegan/vctk_style_melgan.v1", "parallel_wavegan/vctk_hifigan.v1", "parallel_wavegan/libritts_parallel_wavegan.v1.long", "parallel_wavegan/libritts_multi_band_melgan.v2", "parallel_wavegan/libritts_hifigan.v1", "parallel_wavegan/libritts_style_melgan.v1"] {type:"string"}
from espnet2.bin.tts_inference import Text2Speech
from espnet2.utils.types import str_or_none
text2speech = Text2Speech.from_pretrained(
model_tag=str_or_none(tag),
vocoder_tag=str_or_none(vocoder_tag),
device="cuda",
use_att_constraint=False,
backward_window=1,
forward_window=3,
speed_control_alpha=1.0,
)
import glob
import os
import numpy as np
import kaldiio
# Get model directory path
from espnet_model_zoo.downloader import ModelDownloader
d = ModelDownloader()
model_dir = os.path.dirname(d.download_and_unpack(tag)["train_config"])
pdb.set_trace()
# Speaker x-vector selection
xvector_ark = [
p
for p in glob.glob(
f"{model_dir}/../../dump/**/spk_xvector.ark", recursive=True
)
if "tr" in p
][0]
xvectors = {k: v for k, v in kaldiio.load_ark(xvector_ark)}
spks = list(xvectors.keys())
male_spks = {
"M1": "2300_131720",
"M2": "1320_122612",
"M3": "1188_133604",
"M4": "61_70970",
}
female_spks = {"F1": "2961_961", "F2": "8463_287645", "F3": "121_121726"}
spks = dict(male_spks, **female_spks)
spk_names = sorted(spks.keys())
## 20230224 Mousa: No reference,
def ASRold(audio_file):
reg_text = old_transcriber(audio_file)["text"]
return reg_text
def ASRnew(audio_file):
reg_text = transcriber(audio_file)["text"]
return reg_text
def ASRwhipser_FT(audio_file):
reg_text = whisper_transcriber(audio_file)["text"]
return reg_text
def ASRwhipser_Org(audio_file):
reg_text = whisper_transcriber_org(audio_file)["text"]
return reg_text
def ASRwhipser_Tony(audio_file):
reg_text = whisper_transcriber_Tony(audio_file)["text"]
return reg_text
def ASRwhipser_Negel(audio_file):
reg_text = whisper_transcriber_Negel(audio_file)["text"]
return reg_text
def ASRwhipser_John(audio_file):
reg_text = whisper_transcriber_John(audio_file)["text"]
return reg_text
# def ref_reg_callback(audio_file, spk_name, ref_text):
# reg_text = ref_text
# return audio_file, spk_name, reg_text
reference_textbox = gr.Textbox(
value="",
placeholder="Input reference here",
label="Reference",
)
recognization_textbox = gr.Textbox(
value="",
placeholder="Output recognization here",
label="recognization_textbox",
)
speaker_option = gr.Radio(choices=spk_names, label="Speaker")
# speaker_profiles = {
# "Male_1": "speaker_icons/male1.png",
# "Male_2": "speaker_icons/male2.png",
# "Female_1": "speaker_icons/female1.png",
# "Female_2": "speaker_icons/female2.png",
# }
# speaker_option = gr.Image(label="Choose your speaker profile",
# image_mode="RGB",
# options=speaker_profiles
# )
input_audio = gr.Audio(
source="upload", type="filepath", label="Audio_to_Evaluate"
)
output_audio = gr.Audio(
source="upload", file="filepath", label="Synthesized Audio"
)
examples = [
["./samples/001.wav", "M1", ""],
["./samples/002.wav", "M2", ""],
["./samples/003.wav", "F1", ""],
["./samples/004.wav", "F2", ""],
]
def change_audiobox(choice):
if choice == "upload":
input_audio = gr.Audio.update(source="upload", visible=True)
elif choice == "microphone":
input_audio = gr.Audio.update(source="microphone", visible=True)
else:
input_audio = gr.Audio.update(visible=False)
return input_audio
with gr.Blocks(
analytics_enabled=False,
css=".gradio-container {background-color: #78BD91}",
) as demo:
with gr.Column():
input_format = gr.Radio(
choices=["upload", "microphone"], label="Choose your input format"
)
input_audio = gr.Audio(
source="upload",
type="filepath",
label="Input Audio",
interactive=True,
visible=False,
)
input_format.change(
fn=change_audiobox, inputs=input_format, outputs=input_audio
)
with gr.Row():
b1 = gr.Button("Conventional Speech Recognition Engine")
t1 = gr.Textbox(
value="",
placeholder="Recognition output",
label="Convertional",
)
b1.click(
ASRold, inputs=[input_audio], outputs=t1
)
with gr.Row():
b2 = gr.Button("Laronix Speech Recognition Engine (Ver1, wav2vec2.0+CTC)")
t2 = gr.Textbox(
value="",
placeholder="Recognition output",
label="Purposed",
)
b2.click(
ASRnew, inputs=[input_audio], outputs=t2
)
with gr.Row():
b3 = gr.Button("Laronix Speech Recognition Engine (Ver2, Whipser)")
t3 = gr.Textbox(
value="",
placeholder="Recognition output",
label="Purposed",
)
b3.click(
ASRwhipser_FT, inputs=[input_audio], outputs=t3
)
with gr.Row():
b4 = gr.Button("Laronix Speech Recognition Engine (Whipser, FT with Tony)")
t4 = gr.Textbox(
value="",
placeholder="Recognition output",
label="Purposed",
)
b4.click(
ASRwhipser_Tony, inputs=[input_audio], outputs=t4
)
with gr.Row():
b5 = gr.Button("Laronix Speech Recognition Engine (Whipser, FT with John)")
t5 = gr.Textbox(
value="",
placeholder="Recognition output",
label="Purposed",
)
b5.click(
ASRwhipser_John, inputs=[input_audio], outputs=t5
)
with gr.Row():
b6 = gr.Button("Laronix Speech Recognition Engine (Whipser, FT with Negel)")
t6 = gr.Textbox(
value="",
placeholder="Recognition output",
label="Purposed",
)
b6.click(
ASRwhipser_Negel, inputs=[input_audio], outputs=t6
)
demo.launch(share=True)
|