Skip to content

Commit

Permalink
[cli] save embedding to file (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
robin1001 authored Nov 8, 2023
1 parent 6bbaf79 commit e87bd0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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

0 comments on commit e87bd0c

Please sign in to comment.