|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright 2019 Mycroft AI Inc. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +from precise.scripts.add_noise import AddNoiseScript |
| 16 | + |
| 17 | +from test.scripts.dummy_audio_folder import DummyAudioFolder |
| 18 | + |
| 19 | + |
| 20 | +class DummyNoiseFolder(DummyAudioFolder): |
| 21 | + def __init__(self, count=10): |
| 22 | + super().__init__(count) |
| 23 | + self.source = self.subdir('source') |
| 24 | + self.noise = self.subdir('noise') |
| 25 | + self.output = self.subdir('output') |
| 26 | + |
| 27 | + self.generate_samples(self.subdir('source', 'wake-word'), 'ww-{}.wav', 1.0, self.rand(0, 2)) |
| 28 | + self.generate_samples(self.subdir('source', 'not-wake-word'), 'nww-{}.wav', 0.0, self.rand(0, 2)) |
| 29 | + self.generate_samples(self.noise, 'noise-{}.wav', 0.5, self.rand(10, 20)) |
| 30 | + |
| 31 | + |
| 32 | +class TestAddNoise: |
| 33 | + def get_base_data(self, count): |
| 34 | + folders = DummyNoiseFolder(count) |
| 35 | + base_args = dict( |
| 36 | + folder=folders.source, noise_folder=folders.noise, |
| 37 | + output_folder=folders.output |
| 38 | + ) |
| 39 | + return folders, base_args |
| 40 | + |
| 41 | + def test_run_basic(self): |
| 42 | + folders, base_args = self.get_base_data(10) |
| 43 | + script = AddNoiseScript.create(inflation_factor=1, **base_args) |
| 44 | + script.run() |
| 45 | + assert folders.count_files(folders.output) == 20 |
| 46 | + |
| 47 | + def test_run_basic_2(self): |
| 48 | + folders, base_args = self.get_base_data(10) |
| 49 | + script = AddNoiseScript.create(inflation_factor=2, **base_args) |
| 50 | + script.run() |
| 51 | + assert folders.count_files(folders.output) == 40 |
0 commit comments