Auto conversion from .mp3, .ogg to .wav
This commit is contained in:
parent
e53df74d68
commit
d88a84db71
|
@ -437,6 +437,20 @@ def get_songlen(filename):
|
||||||
|
|
||||||
return (len(global_data)/sample_rate)
|
return (len(global_data)/sample_rate)
|
||||||
|
|
||||||
|
def convert_to_wav(song_name:str, output_file="audio.wav") -> str:
|
||||||
|
"""
|
||||||
|
Converts the song to .wav, only if it's not already in wave format.
|
||||||
|
Currently relies on file extension.
|
||||||
|
Returns: the song_name that should be used afterwards.
|
||||||
|
"""
|
||||||
|
extension = Path(song_name).suffix
|
||||||
|
match extension:
|
||||||
|
case ".mp3" | ".ogg":
|
||||||
|
print("Converting to .wav...")
|
||||||
|
subprocess.run(["ffmpeg", "-y", "-i", song_name, output_file])
|
||||||
|
return output_file
|
||||||
|
return song_name
|
||||||
|
|
||||||
def process_song(filename, bpm, offset0=0, div_len_factor=1, n_iter_2=-1, threshold=0.5, divisor=4):
|
def process_song(filename, bpm, offset0=0, div_len_factor=1, n_iter_2=-1, threshold=0.5, divisor=4):
|
||||||
"""
|
"""
|
||||||
filename : string (name of the song)
|
filename : string (name of the song)
|
||||||
|
@ -448,6 +462,8 @@ def process_song(filename, bpm, offset0=0, div_len_factor=1, n_iter_2=-1, thresh
|
||||||
divisor : int [+] (beat divisor used to snap the notes, default is 4)
|
divisor : int [+] (beat divisor used to snap the notes, default is 4)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
filename = convert_to_wav(filename)
|
||||||
|
|
||||||
offset = offset0/1000
|
offset = offset0/1000
|
||||||
|
|
||||||
div_len = div_len_factor*60/bpm-0.01
|
div_len = div_len_factor*60/bpm-0.01
|
||||||
|
@ -470,7 +486,7 @@ def process_song(filename, bpm, offset0=0, div_len_factor=1, n_iter_2=-1, thresh
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
data = process_song("audio.wav", 160, n_iter_2 = 64)
|
data = process_song("tetris_4.wav", 160, n_iter_2 = 64)
|
||||||
#print(data)
|
#print(data)
|
||||||
print("Program finished with return 0")
|
print("Program finished with return 0")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue