Break on Windows, Fix on UNIX
This commit is contained in:
parent
0bafd0d899
commit
3ba8a29dd7
2
main.py
2
main.py
|
@ -3,10 +3,12 @@ import slider as sl
|
|||
from datetime import timedelta
|
||||
import place
|
||||
import sound_process
|
||||
import os
|
||||
import numpy as np
|
||||
|
||||
def main():
|
||||
filename = fd.askopenfilename()
|
||||
os.chdir(os.path.dirname(filename))
|
||||
beatmap = sl.Beatmap.from_path(filename)
|
||||
timing = beatmap.timing_points[0]
|
||||
bpm = timing.bpm
|
||||
|
|
|
@ -30,12 +30,12 @@ def filter_n_percent_serial(song_name, offset, n_iter, step, threshold):
|
|||
filter data associated with song_name to keep only the highest threshold% values
|
||||
"""
|
||||
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(offset+step*n_iter), "-i", song_name, "crop.wav"], shell=True)
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(offset+step*n_iter), "-i", song_name, "crop.wav"], shell=False)
|
||||
|
||||
sample_rate, global_data = wavfile.read('crop.wav')
|
||||
|
||||
subprocess.run(["clear"], shell=True)
|
||||
subprocess.run(["rm", "crop.wav"], shell=True)
|
||||
subprocess.run(["clear"], shell=False)
|
||||
subprocess.run(["rm", "crop.wav"], shell=False)
|
||||
|
||||
for i in range(n_iter):
|
||||
print(i, "/", n_iter)
|
||||
|
@ -97,13 +97,13 @@ def get_freq(song_name, times, width=1000, display=False):
|
|||
for a given list of times (in seconds), returns the corresponding peak frequencies
|
||||
"""
|
||||
|
||||
subprocess.run(["ffmpeg", "-ss", str(0), "-t", str(max(np.array(times))), "-i", song_name, "crop.wav"], shell=True)
|
||||
subprocess.run(["ffmpeg", "-ss", str(0), "-t", str(max(np.array(times))), "-i", song_name, "crop.wav"], shell=False)
|
||||
|
||||
sample_rate, global_data = wavfile.read(song_name)
|
||||
#blit = int(sample_rate*step)
|
||||
|
||||
subprocess.run(["clear"], shell=True)
|
||||
subprocess.run(["rm", "crop.wav"], shell=True)
|
||||
subprocess.run(["clear"], shell=False)
|
||||
subprocess.run(["rm", "crop.wav"], shell=False)
|
||||
|
||||
pfreq = scipy.fft.rfftfreq(2*width, 1/sample_rate)
|
||||
|
||||
|
@ -166,7 +166,7 @@ def void_freq(song_name, offset, songlen, increment, minfreq, maxfreq, upperthr,
|
|||
current_time = offset
|
||||
k = 0
|
||||
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(songlen+offset), "-i", song_name, "crop.wav"], shell=True)
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(songlen+offset), "-i", song_name, "crop.wav"], shell=False)
|
||||
|
||||
sample_rate, raw_global_data = wavfile.read("crop.wav")
|
||||
blit = int(sample_rate*increment)
|
||||
|
@ -174,7 +174,7 @@ def void_freq(song_name, offset, songlen, increment, minfreq, maxfreq, upperthr,
|
|||
global_data = [0 for i in range(len(raw_global_data))]
|
||||
|
||||
#subprocess.run(["clear"])
|
||||
subprocess.run(["rm", "crop.wav"], shell=True)
|
||||
subprocess.run(["rm", "crop.wav"], shell=False)
|
||||
|
||||
a = 0
|
||||
|
||||
|
@ -284,7 +284,7 @@ def convert_to_wav(song_name:str, output_file="audio.wav") -> str:
|
|||
match extension:
|
||||
case ".mp3" | ".ogg":
|
||||
print("Converting to .wav...")
|
||||
subprocess.run(["ffmpeg", "-y", "-i", song_name, output_file], shell=True)
|
||||
subprocess.run(["ffmpeg", "-y", "-i", song_name, output_file], shell=False)
|
||||
return output_file
|
||||
return song_name
|
||||
|
||||
|
@ -454,13 +454,13 @@ def fct(song_name, offset, increment, songlen, maxfreq, display):
|
|||
current_time = offset
|
||||
k = 0
|
||||
while(current_time <= songlen):
|
||||
subprocess.run(["ffmpeg", "-ss", str(current_time), "-t", str(increment), "-i", song_name, "crop.wav"], shell=True)
|
||||
subprocess.run(["ffmpeg", "-ss", str(current_time), "-t", str(increment), "-i", song_name, "crop.wav"], shell=False)
|
||||
|
||||
sample_rate, audio_data = wavfile.read('crop.wav')
|
||||
size = audio_data.size
|
||||
|
||||
#subprocess.run(["clear"])
|
||||
subprocess.run(["rm", "crop.wav"], shell=True)
|
||||
subprocess.run(["rm", "crop.wav"], shell=False)
|
||||
|
||||
# do stuff here
|
||||
#f, t, Zxx = signal.stft(audio_data, sample_rate, nperseg=1000)
|
||||
|
@ -603,12 +603,12 @@ def extract_peaks_v2(song_data, sample_rate, offset, display, threshold, seglen)
|
|||
return (t, song_data)
|
||||
|
||||
def peaks(song_name, offset, length, display, thr):
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(length), "-i", song_name, "crop.wav"], shell=True)
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(length), "-i", song_name, "crop.wav"], shell=False)
|
||||
|
||||
sample_rate, audio_data = wavfile.read('crop.wav')
|
||||
|
||||
#subprocess.run(["clear"])
|
||||
subprocess.run(["rm", "crop.wav"], shell=True)
|
||||
subprocess.run(["rm", "crop.wav"], shell=False)
|
||||
|
||||
#return extract_peaks(audio_data, sample_rate, offset, display, thr)
|
||||
return extract_peaks_v2(audio_data, sample_rate, offset, display, thr, 44100*2)
|
||||
|
@ -813,12 +813,12 @@ def filter_n_percent(song_name, offset, length, threshold, reduce, show):
|
|||
# threshold is in ]0, 100]
|
||||
# filter data associated with song_name to keep only the highest threshold% values
|
||||
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(length), "-i", song_name, "crop.wav"], shell=True)
|
||||
subprocess.run(["ffmpeg", "-ss", str(offset), "-t", str(length), "-i", song_name, "crop.wav"], shell=False)
|
||||
|
||||
sample_rate, song_data = wavfile.read('crop.wav')
|
||||
|
||||
subprocess.run(["clear"], shell=True)
|
||||
subprocess.run(["rm", "crop.wav"], shell=True)
|
||||
subprocess.run(["clear"], shell=False)
|
||||
subprocess.run(["rm", "crop.wav"], shell=False)
|
||||
|
||||
if(reduce):
|
||||
(song_data,e) = to_ms(song_data, 44100, 1)
|
||||
|
|
Loading…
Reference in New Issue