summaryrefslogtreecommitdiff
path: root/scripts/py/rnnoise_dump_extractor.py
diff options
context:
space:
mode:
authorRichard Burton <richard.burton@arm.com>2022-03-17 10:54:26 +0000
committerRichard <richard.burton@arm.com>2022-03-17 15:19:16 +0000
commit17069628a7f28198652a296ac16dc83529c7eaae (patch)
treeadff78b64954e67dc4e29f6f039c63c8c18cde2c /scripts/py/rnnoise_dump_extractor.py
parent624dafd2a206d88da979453442fe5a8d4c05ad51 (diff)
downloadml-embedded-evaluation-kit-17069628a7f28198652a296ac16dc83529c7eaae.tar.gz
MLECO-3036: Update to use Pathlib in Python scripts
* Pathlib used in Python scripts over os * Bug fix for build_default.py * Minor code style updates Signed-off-by: Richard Burton <richard.burton@arm.com> Change-Id: I5fc2e582a84443c3fb79250eb711b960d63ed8fd
Diffstat (limited to 'scripts/py/rnnoise_dump_extractor.py')
-rw-r--r--scripts/py/rnnoise_dump_extractor.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/scripts/py/rnnoise_dump_extractor.py b/scripts/py/rnnoise_dump_extractor.py
index 947a75a..ff79dcb 100644
--- a/scripts/py/rnnoise_dump_extractor.py
+++ b/scripts/py/rnnoise_dump_extractor.py
@@ -12,7 +12,6 @@
# 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 script can be used with the noise reduction use case to save
the dumped noise reduced audio to a wav file.
@@ -20,14 +19,15 @@ the dumped noise reduced audio to a wav file.
Example use:
python rnnoise_dump_extractor.py --dump_file output.bin --output_dir ./denoised_wavs/
"""
+
import soundfile as sf
import numpy as np
import argparse
from os import path
-
import struct
+
def extract(fp, output_dir, export_npy):
while True:
filename_length = struct.unpack("i", fp.read(4))[0]
@@ -47,19 +47,20 @@ def extract(fp, output_dir, export_npy):
if export_npy:
output_file_name += ".npy"
pack_format = "{}h".format(int(audio_clip_length/2))
- npdata = np.array(struct.unpack(pack_format,audio_clip)).astype(np.int16)
+ npdata = np.array(struct.unpack(pack_format, audio_clip)).astype(np.int16)
np.save(output_file_name, npdata)
print("{} written to disk".format(output_file_name))
+
def main(args):
extract(args.dump_file, args.output_dir, args.export_npy)
+
parser = argparse.ArgumentParser()
parser.add_argument("--dump_file", type=argparse.FileType('rb'), help="Dump file with audio files to extract.", required=True)
parser.add_argument("--output_dir", help="Output directory, Warning: Duplicated file names will be overwritten.", required=True)
parser.add_argument("--export_npy", help="Export the audio buffer in NumPy format", action="store_true")
args = parser.parse_args()
-if __name__=="__main__":
+if __name__ == "__main__":
main(args)
-