Skip to content

[cli] save embedding to file #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pip install git+https://github.com/wenet-e2e/wespeaker.git
**Command-line usage** (use `-h` for parameters):

``` sh
$ wespeaker --task embedding --audio_file audio.wav
$ wespeaker --task embedding --audio_file audio.wav --output_file embedding.txt
$ wespeaker --task similarity --audio_file audio.wav --audio_file2 audio2.wav
$ wespeaker --task diarization --audio_file audio.wav # TODO
```
Expand Down
9 changes: 8 additions & 1 deletion wespeaker/cli/speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def get_args():
parser.add_argument('--vad',
action='store_true',
help='whether to do VAD or not')
parser.add_argument('--output_file',
help='output file to save speaker embedding')
args = parser.parse_args()
return args

Expand All @@ -137,7 +139,12 @@ def main():
args = get_args()
model = load_model(args.language, args.resample_rate)
if args.task == 'embedding':
print(model.extract_embedding(args.audio_file, args.vad))
embedding = model.extract_embedding(args.audio_file, args.vad)
if embedding is not None:
np.savetxt(args.output_file, embedding)
print('Succeed, see {}'.format(args.output_file))
else:
print('Fails to extract embedding')
elif args.task == 'similarity':
print(model.compute_similarity(args.audio_file, args.audio_file2))
elif args.task == 'diarization':
Expand Down