Skip to content

Commit 6ffe3f8

Browse files
Move script help strings to docstrings
1 parent 20be762 commit 6ffe3f8

File tree

17 files changed

+387
-370
lines changed

17 files changed

+387
-370
lines changed

precise/pocketsphinx/scripts/listen.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
"""
16+
Run Pocketsphinx on microphone audio input
17+
18+
:key_phrase str
19+
Key phrase composed of words from dictionary
20+
21+
:dict_file str
22+
Filename of dictionary with word pronunciations
23+
24+
:hmm_folder str
25+
Folder containing hidden markov model
26+
27+
:-th --threshold str 1e-90
28+
Threshold for activations
29+
30+
:-c --chunk-size int 2048
31+
Samples between inferences
32+
"""
1533
from precise_runner import PreciseRunner
1634
from precise_runner.runner import ListenerEngine
1735
from prettyparse import Usage
@@ -23,24 +41,7 @@
2341

2442

2543
class PocketsphinxListenScript(BaseScript):
26-
usage = Usage('''
27-
Run Pocketsphinx on microphone audio input
28-
29-
:key_phrase str
30-
Key phrase composed of words from dictionary
31-
32-
:dict_file str
33-
Filename of dictionary with word pronunciations
34-
35-
:hmm_folder str
36-
Folder containing hidden markov model
37-
38-
:-th --threshold str 1e-90
39-
Threshold for activations
40-
41-
:-c --chunk-size int 2048
42-
Samples between inferences
43-
''')
44+
usage = Usage(__doc__)
4445

4546
def run(self):
4647
def on_activation():

precise/pocketsphinx/scripts/test.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,29 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
"""
16+
Test a dataset using Pocketsphinx
17+
18+
:key_phrase str
19+
Key phrase composed of words from dictionary
20+
21+
:dict_file str
22+
Filename of dictionary with word pronunciations
23+
24+
:hmm_folder str
25+
Folder containing hidden markov model
26+
27+
:-th --threshold str 1e-90
28+
Threshold for activations
29+
30+
:-t --use-train
31+
Evaluate training data instead of test data
32+
33+
:-nf --no-filenames
34+
Don't show the names of files that failed
35+
36+
...
37+
"""
1538
import wave
1639
from prettyparse import Usage
1740
from subprocess import check_output, PIPE
@@ -23,29 +46,7 @@
2346

2447

2548
class PocketsphinxTestScript(BaseScript):
26-
usage = Usage('''
27-
Test a dataset using Pocketsphinx
28-
29-
:key_phrase str
30-
Key phrase composed of words from dictionary
31-
32-
:dict_file str
33-
Filename of dictionary with word pronunciations
34-
35-
:hmm_folder str
36-
Folder containing hidden markov model
37-
38-
:-th --threshold str 1e-90
39-
Threshold for activations
40-
41-
:-t --use-train
42-
Evaluate training data instead of test data
43-
44-
:-nf --no-filenames
45-
Don't show the names of files that failed
46-
47-
...
48-
''') | TrainData.usage
49+
usage = Usage(__doc__) | TrainData.usage
4950

5051
def __init__(self, args):
5152
super().__init__(args)

precise/scripts/add_noise.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,30 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
"""
16+
Create a duplicate dataset with added noise
17+
18+
:folder str
19+
Folder containing source dataset
20+
21+
:-tg --tags-file str -
22+
Tags file to optionally load from
23+
24+
:noise_folder str
25+
Folder with wav files containing noise to be added
26+
27+
:output_folder str
28+
Folder to write the duplicate generated dataset
29+
30+
:-if --inflation-factor int 1
31+
The number of noisy samples generated per single source sample
32+
33+
:-nl --noise-ratio-low float 0.0
34+
Minimum random ratio of noise to sample. 1.0 is all noise, no sample sound
35+
36+
:-nh --noise-ratio-high float 0.4
37+
Maximum random ratio of noise to sample. 1.0 is all noise, no sample sound
38+
"""
1539
from math import sqrt
1640

1741
import numpy as np
@@ -68,30 +92,7 @@ def noised_audio(self, audio: np.ndarray, noise_ratio: float) -> np.ndarray:
6892

6993
class AddNoiseScript(BaseScript):
7094
usage = Usage(
71-
"""
72-
Create a duplicate dataset with added noise
73-
74-
:folder str
75-
Folder containing source dataset
76-
77-
:-tg --tags-file str -
78-
Tags file to optionally load from
79-
80-
:noise_folder str
81-
Folder with wav files containing noise to be added
82-
83-
:output_folder str
84-
Folder to write the duplicate generated dataset
85-
86-
:-if --inflation-factor int 1
87-
The number of noisy samples generated per single source sample
88-
89-
:-nl --noise-ratio-low float 0.0
90-
Minimum random ratio of noise to sample. 1.0 is all noise, no sample sound
91-
92-
:-nh --noise-ratio-high float 0.4
93-
Maximum random ratio of noise to sample. 1.0 is all noise, no sample sound
94-
""",
95+
__doc__,
9596
tags_file=lambda args: abspath(args.tags_file) if args.tags_file else None,
9697
folder=lambda args: abspath(args.folder),
9798
output_folder=lambda args: abspath(args.output_folder)

precise/scripts/calc_threshold.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License
15+
"""
16+
Update the threshold values of a model for a dataset.
17+
This makes the sensitivity more accurate and linear
18+
19+
:model str
20+
Either Keras (.net) or TensorFlow (.pb) model to adjust
21+
22+
:input_file str
23+
Input stats file that was outputted from precise-graph
24+
25+
:-k --model-key str -
26+
Custom model name to use from the stats.json
27+
28+
:-s --smoothing float 1.2
29+
Amount of extra smoothing to apply
30+
31+
:-c --center float 0.2
32+
Decoded threshold that is mapped to 0.5. Proportion of
33+
false negatives at sensitivity=0.5
34+
"""
1535
from math import sqrt
1636

1737
from os.path import basename, splitext
@@ -23,26 +43,7 @@
2343

2444

2545
class CalcThresholdScript(BaseScript):
26-
usage = Usage('''
27-
Update the threshold values of a model for a dataset.
28-
This makes the sensitivity more accurate and linear
29-
30-
:model str
31-
Either Keras (.net) or TensorFlow (.pb) model to adjust
32-
33-
:input_file str
34-
Input stats file that was outputted from precise-graph
35-
36-
:-k --model-key str -
37-
Custom model name to use from the stats.json
38-
39-
:-s --smoothing float 1.2
40-
Amount of extra smoothing to apply
41-
42-
:-c --center float 0.2
43-
Decoded threshold that is mapped to 0.5. Proportion of
44-
false negatives at sensitivity=0.5
45-
''')
46+
usage = Usage(__doc__)
4647

4748
def __init__(self, args):
4849
super().__init__(args)

precise/scripts/collect.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
"""
16+
Record audio samples for use with precise
17+
18+
:-w --width int 2
19+
Sample width of audio
20+
21+
:-r --rate int 16000
22+
Sample rate of audio
23+
24+
:-c --channels int 1
25+
Number of audio channels
26+
"""
1527
from select import select
1628
from sys import stdin
1729
from termios import tcsetattr, tcgetattr, TCSADRAIN
@@ -53,18 +65,7 @@ class CollectScript(BaseScript):
5365
RECORD_KEY = ' '
5466
EXIT_KEY_CODE = 27
5567

56-
usage = Usage('''
57-
Record audio samples for use with precise
58-
59-
:-w --width int 2
60-
Sample width of audio
61-
62-
:-r --rate int 16000
63-
Sample rate of audio
64-
65-
:-c --channels int 1
66-
Number of audio channels
67-
''')
68+
usage = Usage(__doc__)
6869
usage.add_argument('file_label', nargs='?', help='File label (Ex. recording-##)')
6970

7071
def __init__(self, args):

precise/scripts/convert.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16+
"""
17+
Convert wake word model from Keras to TensorFlow
18+
19+
:model str
20+
Input Keras model (.net)
21+
22+
:-o --out str {model}.pb
23+
Custom output TensorFlow protobuf filename
24+
"""
1625
import os
1726
from os.path import split, isfile
1827
from prettyparse import Usage
@@ -22,15 +31,7 @@
2231

2332

2433
class ConvertScript(BaseScript):
25-
usage = Usage('''
26-
Convert wake word model from Keras to TensorFlow
27-
28-
:model str
29-
Input Keras model (.net)
30-
31-
:-o --out str {model}.pb
32-
Custom output TensorFlow protobuf filename
33-
''')
34+
usage = Usage(__doc__)
3435

3536
def run(self):
3637
args = self.args

precise/scripts/engine.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
"""
16+
stdin should be a stream of raw int16 audio, written in
17+
groups of CHUNK_SIZE samples. If no CHUNK_SIZE is given
18+
it will read until EOF. For every chunk, an inference
19+
will be given via stdout as a float string, one per line
20+
21+
:model_name str
22+
Keras or TensorFlow model to read from
23+
24+
...
25+
"""
1526
import sys
1627

1728
import os
@@ -27,17 +38,7 @@ def add_audio_pipe_to_parser(parser):
2738

2839

2940
class EngineScript(BaseScript):
30-
usage = Usage('''
31-
stdin should be a stream of raw int16 audio, written in
32-
groups of CHUNK_SIZE samples. If no CHUNK_SIZE is given
33-
it will read until EOF. For every chunk, an inference
34-
will be given via stdout as a float string, one per line
35-
36-
:model_name str
37-
Keras or TensorFlow model to read from
38-
39-
...
40-
''')
41+
usage = Usage(__doc__)
4142
usage.add_argument('-v', '--version', action='version', version=__version__)
4243
usage.add_argument('chunk_size', type=int, nargs='?', default=-1,
4344
help='Number of bytes to read before making a prediction. '

0 commit comments

Comments
 (0)