Add Python API examples for speaker recognition with VAD and ASR. (#532)

This commit is contained in:
Fangjun Kuang
2024-01-15 21:40:30 +08:00
committed by GitHub
parent 7e0ae677c8
commit 59e28518b4
3 changed files with 750 additions and 4 deletions

View File

@@ -1,7 +1,8 @@
#!/usr/bin/env python3
"""
This script shows how to use Python APIs for speaker identification.
This script shows how to use Python APIs for speaker identification with
a microphone.
Usage:
@@ -43,6 +44,7 @@ python3 ./python-api-examples/speaker-identification.py \
"""
import argparse
import queue
import sys
import threading
from collections import defaultdict
from pathlib import Path
@@ -151,7 +153,7 @@ def compute_speaker_embedding(
filenames: List[str],
extractor: sherpa_onnx.SpeakerEmbeddingExtractor,
) -> np.ndarray:
assert len(filenames) > 0, f"filenames is empty"
assert len(filenames) > 0, "filenames is empty"
ans = None
for filename in filenames:
@@ -215,7 +217,7 @@ def main():
global g_stop
global g_read_mic_thread
while True:
key = input("Press enter to start recording")
key = input("Press Enter to start recording")
if key.lower() in ("q", "quit"):
g_stop = True
break
@@ -224,7 +226,7 @@ def main():
g_buffer.queue.clear()
g_read_mic_thread = threading.Thread(target=read_mic)
g_read_mic_thread.start()
input("Press enter to stop recording")
input("Press Enter to stop recording")
g_stop = True
g_read_mic_thread.join()
print("Compute embedding")