-
Notifications
You must be signed in to change notification settings - Fork 419
/
google_speech_commands_corpus.py
68 lines (53 loc) · 1.88 KB
/
google_speech_commands_corpus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Google Speech Commands Dataset
=================
Pyroomacoustics includes a wrapper around the Google Speech Commands dataset.
More info about the dataset can be found at the link below:
https://research.googleblog.com/2017/08/launching-speech-commands-dataset.html
"""
import argparse
import os
import pyroomacoustics as pra
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Example of using the GoogleSpeechCommands wrapper"
)
parser.add_argument("--noplot", action="store_true", help="Do not display any plot")
parser.add_argument(
"--playsound", action="store_true", help="Play one example sentence"
)
args = parser.parse_args()
# create a subset of the Google Speech Commands dataset that contains 10 of each
# word and the noise samples
dataset = pra.datasets.GoogleSpeechCommands(download=True, subset=10)
# print dataset info and first 10 entries
print(dataset)
print()
dataset.head(n=10)
# separate the noise and the speech samples
print()
noise_samps = dataset.filter(speech=0)
print("Number of noise samples : %d" % len(noise_samps))
speech_samps = dataset.filter(speech=1)
print("Number of speech samples : %d" % len(speech_samps))
# print info of first speech sample
print()
print(speech_samps[0])
# list sounds in our dataset and number of occurences
print()
print("All sounds in the dataset:")
print(dataset.classes)
# filter by specific word
selected_word = dataset.classes[1]
matches = speech_samps.filter(word=selected_word)
print()
print("Number of '%s' samples : %d" % (selected_word, len(matches)))
# play sound
if args.playsound:
matches[0].play()
# show the spectrogram
if not args.noplot:
import matplotlib.pyplot as plt
plt.figure()
matches[0].plot()
plt.show()