-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/add_create_mn_test_doc' into 'master'
Feat/add create mn test doc See merge request speech-recognition-framework/esp-skainet!36
- Loading branch information
Showing
3 changed files
with
167 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/python3 | ||
|
||
# This Python script is an example for creating the JSON file required by `create_mn_test_set.py` | ||
|
||
import argparse | ||
import json | ||
import random | ||
from pathlib import Path | ||
|
||
import torchaudio | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--wake-word-dir", | ||
type=str, | ||
help="directory of wake word recordings" | ||
) | ||
parser.add_argument( | ||
"--command-dir", | ||
type=str, | ||
help="directory of command recordings" | ||
) | ||
parser.add_argument( | ||
"--out-file", | ||
type=str, | ||
help="output filename" | ||
) | ||
args = parser.parse_args() | ||
|
||
wakewords = list(Path(args.wake_word_dir).glob("*.wav")) | ||
commands = list(Path(args.command_dir).glob("*.wav")) | ||
|
||
output = [] | ||
|
||
for wakeword in wakewords: | ||
data, sr = torchaudio.load(wakeword) | ||
assert sr == 16000, sr | ||
block = { | ||
"wake_word_fname": wakeword.name, | ||
"size": data.shape[1], | ||
"wake_word_tailing_silence_ms": 100, | ||
"commands": [], | ||
"between_command_length_ms": 5000, | ||
} | ||
num_command = random.randint(1, 5) | ||
block_commands = random.sample(commands, num_command) | ||
for command in block_commands: | ||
data, sr = torchaudio.load(wakeword) | ||
assert sr == 16000, sr | ||
block["commands"].append( | ||
{ | ||
"command_fname": command.name, | ||
"size": data.shape[1] | ||
} | ||
) | ||
output.append(block) | ||
|
||
with open(args.out_file, "wt") as f: | ||
json.dump(output, f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters