-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudio.py
More file actions
28 lines (22 loc) · 731 Bytes
/
Copy pathAudio.py
File metadata and controls
28 lines (22 loc) · 731 Bytes
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
#import all libraries
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
#import to read/write wav audio files
from scipy.io.wavfile import read
from scipy.io.wavfile import write
#declare global variables
song_path = './data/Faded.wav'
def audio_2_array(path):
a = read(path)
return np.array(a[1],dtype=float)
def array_2_audio(audio_array,filename = 'test',samplerate= 44100):
a_file = str('./data/' + filename + '.wav')
scaled = np.int16(audio_array/np.max(np.abs(audio_array)) * 32767)
write(a_file, samplerate, scaled)
return 0
song = audio_2_array(song_path)
array_2_audio(song)
#Reverse song - @@$$
rev_song = np.flip(song)
array_2_audio(rev_song,filename='rev_audio')