-
Notifications
You must be signed in to change notification settings - Fork 2
/
audio_processor.py
43 lines (29 loc) · 972 Bytes
/
audio_processor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import numpy as np
import scipy.io.wavfile as wavfile
# Parameters
# **********
# This must be an audio file readable by scipy.io.wavfile.read() function
input_file = 'Marimba.wav'
output_file = 'output.wav'
# Read input file
# ***************
fs, input_data = wavfile.read(input_file, mmap=True)
# convert to float
max_value = float(-np.iinfo(input_data.dtype).min)
input_data = input_data.astype('float32') / max_value
# convert to mono if not already
if len(input_data.shape) > 1:
input_data = np.mean(input_data, axis=1)
input_data = input_data.flatten()
# Audio data process
# ******************
output_data = np.zeros(len(input_data))
# *************************
# * PROCESSING COMES HERE *
# *************************
output_data = input_data
# *************************
# Save output
# ***********
output_data = 0.99 * output_data / max(abs(output_data))
wavfile.write(output_file, int(fs), (output_data*np.iinfo(np.int16).max).astype(np.int16))