Spaces:
Runtime error
Runtime error
| import ssl | |
| ssl._create_default_https_context = ssl._create_unverified_context | |
| import gradio as gr | |
| import wespeaker | |
| STYLE = """ | |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha256-YvdLHPgkqJ8DVUxjjnGVlMMJtNimJ6dYkowFFvp4kKs=" crossorigin="anonymous"> | |
| """ | |
| OUTPUT_OK = (STYLE + """ | |
| <div class="container"> | |
| <div class="row"><h1 style="text-align: center">The speakers are</h1></div> | |
| <div class="row"><h1 class="display-1 text-success" style="text-align: center">{:.1f}%</h1></div> | |
| <div class="row"><h1 style="text-align: center">similar</h1></div> | |
| <div class="row"><h1 class="text-success" style="text-align: center">Welcome, brother!</h1></div> | |
| </div> | |
| """) | |
| OUTPUT_FAIL = (STYLE + """ | |
| <div class="container"> | |
| <div class="row"><h1 style="text-align: center">The speakers are</h1></div> | |
| <div class="row"><h1 class="display-1 text-danger" style="text-align: center">{:.1f}%</h1></div> | |
| <div class="row"><h1 style="text-align: center">similar</h1></div> | |
| <div class="row"><h1 class="text-danger" style="text-align: center">Warning! stranger!</h1></div> | |
| </div> | |
| """) | |
| OUTPUT_ERROR = (STYLE + """ | |
| <div class="container"> | |
| <div class="row"><h1 style="text-align: center">Input Error</h1></div> | |
| <div class="row"><h1 class="text-danger" style="text-align: center">{}!</h1></div> | |
| </div> | |
| """) | |
| cn_model = wespeaker.load_model("chinese") | |
| en_model = wespeaker.load_model("english") | |
| def speaker_verification(audio_path1, audio_path2, lang='CN'): | |
| if audio_path1 == None or audio_path2 == None: | |
| output = OUTPUT_ERROR.format('Please enter two audios') | |
| return output | |
| if lang == 'EN': | |
| model = en_model | |
| elif lang == 'CN': | |
| model = cn_model | |
| else: | |
| output = OUTPUT_ERROR.format('Please select a language') | |
| return output | |
| cos_score = model.compute_similarity(audio_path1, audio_path2) | |
| if cos_score >= 0.83: | |
| output = OUTPUT_OK.format(cos_score * 100) | |
| else: | |
| output = OUTPUT_FAIL.format(cos_score * 100) | |
| return output | |
| # input | |
| inputs = [ | |
| gr.inputs.Audio(source="microphone", | |
| type="filepath", | |
| optional=True, | |
| label='Speaker#1'), | |
| gr.inputs.Audio(source="microphone", | |
| type="filepath", | |
| optional=True, | |
| label='Speaker#2'), | |
| gr.Radio(['EN', 'CN'], label='Language'), | |
| ] | |
| output = gr.outputs.HTML(label="") | |
| # description | |
| description = ("<p>VoicePrint Demo ! Note: We recommend that the audio length be greater than 2s !</p>") | |
| examples = [ | |
| ['examples/BAC009S0764W0228.wav', 'examples/BAC009S0764W0328.wav', 'CN'], | |
| ['examples/BAC009S0913W0133.wav', 'examples/BAC009S0764W0228.wav', 'CN'], | |
| ['examples/00001_spk1.wav', 'examples/00003_spk2.wav', 'EN'], | |
| ['examples/00010_spk2.wav', 'examples/00024_spk1.wav', 'EN'], | |
| ['examples/00001_spk1.wav', 'examples/00024_spk1.wav', 'EN'], | |
| ['examples/00010_spk2.wav', 'examples/00003_spk2.wav', 'EN'], | |
| ] | |
| interface = gr.Interface( | |
| fn=speaker_verification, | |
| inputs=inputs, | |
| outputs=output, | |
| title="VoicePrint Recognition-声纹识别", | |
| description=description, | |
| examples=examples, | |
| theme="huggingface", | |
| ) | |
| interface.launch(enable_queue=True,server_name="0.0.0.0",server_port=10001) | |