-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixtures are used consistently A new TempFolder class has been created for reusability A session-wide trained_model fixture has been added to speed up testing
- Loading branch information
1 parent
1c7cd51
commit a6fc615
Showing
10 changed files
with
182 additions
and
80 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
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
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
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,13 @@ | ||
# Copyright 2020 Mycroft AI Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
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,35 @@ | ||
# Copyright 2020 Mycroft AI Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import numpy as np | ||
|
||
from test.scripts.test_utils.temp_folder import TempFolder | ||
from test.scripts.test_utils.dummy_train_folder import DummyTrainFolder | ||
|
||
|
||
class DummyNoiseFolder(TempFolder): | ||
def __init__(self): | ||
super().__init__() | ||
self.source = self.subdir('source') | ||
self.noise = self.subdir('noise') | ||
self.output = self.subdir('output') | ||
|
||
self.source_folder = DummyTrainFolder(root=self.source) | ||
self.noise_folder = DummyTrainFolder(root=self.noise) | ||
|
||
def generate_default(self, count=10): | ||
self.source_folder.generate_default(count) | ||
self.noise_folder.generate_samples( | ||
count, [], 'noise-{}.wav', | ||
lambda: np.ones(self.noise_folder.get_duration(), dtype=float) | ||
) |
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,68 @@ | ||
# Copyright 2020 Mycroft AI Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import random | ||
from os.path import join | ||
|
||
import numpy as np | ||
|
||
from precise.params import pr | ||
from precise.util import save_audio | ||
from test.scripts.test_utils.temp_folder import TempFolder | ||
|
||
|
||
class DummyTrainFolder(TempFolder): | ||
def __init__(self, root=None): | ||
super().__init__(root) | ||
self.model = self.path('model.net') | ||
|
||
def generate_samples(self, count, subfolder, name, generator): | ||
""" | ||
Generate sample audio files in a folder | ||
The file is generated in the specified folder, with the specified | ||
name and generated value. | ||
Args: | ||
count: Number of samples to generate | ||
subfolder: String or list of subfolder path | ||
name: Format string used to generate each sample | ||
generator: Function called to get the data for each sample | ||
""" | ||
if isinstance(subfolder, str): | ||
subfolder = [subfolder] | ||
for i in range(count): | ||
save_audio(join(self.subdir(*subfolder), name.format(i)), generator()) | ||
|
||
def get_duration(self): | ||
"""Generate a random sample duration""" | ||
return int(random.random() * 2 * pr.buffer_samples) | ||
|
||
def generate_default(self, count=10): | ||
self.generate_samples( | ||
count, 'wake-word', 'ww-{}.wav', | ||
lambda: np.ones(self.get_duration(), dtype=float) | ||
) | ||
self.generate_samples( | ||
count, 'not-wake-word', 'nww-{}.wav', | ||
lambda: np.random.random(self.get_duration()) * 2 - 1 | ||
) | ||
self.generate_samples( | ||
count, ('test', 'wake-word'), 'ww-{}.wav', | ||
lambda: np.ones(self.get_duration(), dtype=float) | ||
) | ||
self.generate_samples( | ||
count, ('test', 'not-wake-word'), 'nww-{}.wav', | ||
lambda: np.random.random(self.get_duration()) * 2 - 1 | ||
) | ||
self.model = self.path('model.net') |
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