summaryrefslogtreecommitdiff
path: root/scripts/py/rnnoise_dump_extractor.py
diff options
context:
space:
mode:
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)
-