def get_song(i): # get random beatmap dir beatmap_folder = path.join(songs_folder, os.listdir(songs_folder)[i]) beatmap_list = [f for f in os.listdir(beatmap_folder) if f[-4:] == ".osu"] beatmap_path = path.join(beatmap_folder, random.choice(beatmap_list)) # open the beatmap beatmap = osureader.readBeatmap(beatmap_path) # find the audio audio_path = path.join(beatmap_folder, beatmap.AudioFilename) # open the audio wav_path = path.join(beatmap_folder, "audio.wav.wav") if not path.exists(wav_path): subprocess.call([ 'ffmpeg', '-i', audio_path, "-ar", str(sampling_rate), "-ac", "1", wav_path ]) audio = read(wav_path) if not audio[0] == sampling_rate: ## os.remove(wav_path) subprocess.call([ 'ffmpeg', '-i', audio_path, "-ar", str(sampling_rate), "-ac", "1", wav_path ]) audio = read(wav_path) audio = audio[1] return audio, beatmap, wav_path
def generate_test(folder, offset): beatmap_list = [f for f in os.listdir(folder) if f[-4:] == ".osu"] beatmap_path = path.join(folder, beatmap_list[0]) x_list = [] times = [] beatmap = osureader.readBeatmap(beatmap_path) audio_path = path.join(folder, beatmap.AudioFilename) wav_path = path.join(folder, "audio.wav.wav") if not path.exists(wav_path): subprocess.call(['ffmpeg', '-i', audio_path, "-ar", str(sampling_rate), "-ac", "1", wav_path]) audio = read(wav_path) if not audio[0] == sampling_rate: os.remove(wav_path) subprocess.call(['ffmpeg', '-i', audio_path, "-ar", str(sampling_rate), "-ac", "1", wav_path]) audio = read(wav_path) audio = audio[1] print(beatmap.Title) audio_ms = len(audio) / sampling_rate * 1000 redpoints = [] for tp in beatmap.TimingPoints: if tp[6] == 1: redpoints.append(tp) for index in range(len(redpoints) - 1): rp = redpoints[index] time = rp[0] while time + 30 < redpoints[index + 1][0]: audio_index = int(time * sampling_rate / 1000) - audio_size // 2 + offset if audio_index >= 0: x_list.append(audio[audio_index:audio_index + audio_size]) times.append(time) time += rp[1] / 4 rp = redpoints[-1] time = rp[0] while time + 200 < audio_ms: audio_index = int(time * sampling_rate / 1000) - audio_size // 2 + offset if audio_index >= 0: x_list.append(audio[audio_index:audio_index + audio_size]) times.append(time) time += rp[1] / 4 x = np.vstack(x_list) x = np.divide(x, 32767) return x.astype(np.float32, copy=False), times
def getRandomSong(): #get random beatmap dir notFoundMap = True while notFoundMap: beatmap_folder = path.join(data_folder, random.choice(os.listdir(data_folder))) beatmap_list = [ f for f in os.listdir(beatmap_folder) if f[-4:] == ".osu" ] if len(beatmap_list) == 0: pass #print("Empty beatmap folder detected. Deleting the folder from training directory") #os.remove(beatmap_folder) else: beatmap_path = path.join(beatmap_folder, random.choice(beatmap_list)) #open the beatmap beatmap = osureader.readBeatmap(beatmap_path) #find the audio audio_path = path.join(beatmap_folder, beatmap.AudioFilename) if validateBeatmap(beatmap) and path.isfile(audio_path): notFoundMap = False #find the audio audio_path = path.join(beatmap_folder, beatmap.AudioFilename) #open the audio wav_path = path.join(beatmap_folder, "audio.wav.wav") if not path.exists(wav_path): subprocess.call([ 'ffmpeg', '-i', audio_path, "-ar", str(sampling_rate), "-ac", "1", wav_path ]) audio = read(wav_path) if not audio[0] == sampling_rate: os.remove(wav_path) subprocess.call([ 'ffmpeg', '-i', audio_path, "-ar", str(sampling_rate), "-ac", "1", wav_path ]) audio = read(wav_path) audio = audio[1] return (audio, beatmap)
def get_audio(folder): beatmap_list = [f for f in os.listdir(folder) if f[-4:] == ".osu"] audio_path = None wav_path = None audio_filename = None if len(beatmap_list) > 0: beatmap_path = path.join(folder, beatmap_list[0]) beatmap = osureader.readBeatmap(beatmap_path) audio_filename = beatmap.AudioFilename audio_path = path.join(folder, audio_filename) wav_path = path.join(folder, "audio.wav.wav") print(beatmap.Title) else: mp3_list = [f for f in os.listdir(folder) if f[-4:] == ".mp3"] audio_filename = mp3_list[0] audio_path = path.join(folder, audio_filename) wav_path = path.join(folder, "audio.wav.wav") print(mp3_list[0]) if not path.exists(wav_path): subprocess.call([ 'ffmpeg', '-i', audio_path, "-ar", str(sampling_rate), "-ac", "1", wav_path ]) audio = read(wav_path) if not audio[0] == sampling_rate: os.remove(wav_path) subprocess.call([ 'ffmpeg', '-i', audio_path, "-ar", str(sampling_rate), "-ac", "1", wav_path ]) audio = read(wav_path) audio = audio[1] audio_ms = len(audio) / sampling_rate * 1000 audio = np.divide( np.concatenate( (np.zeros(audio_size // 2), audio, np.zeros(audio_size // 2))), 32767) return audio, audio_ms, audio_filename
def generate_test(folder): beatmap_list = [f for f in os.listdir(folder) if f[-4:] == ".osu"] beatmap_path = path.join(folder, beatmap_list[0]) x_list = [] times = [] tick_list = [] beatmap = osureader.readBeatmap(beatmap_path) audio_path = path.join(folder, beatmap.AudioFilename) wav_path = path.join(folder, "audio.wav.wav") if not path.exists(wav_path): subprocess.call([ 'ffmpeg', '-i', audio_path, "-ar", str(sampling_rate), "-ac", "1", wav_path ]) audio = read(wav_path) if not audio[0] == sampling_rate: os.remove(wav_path) subprocess.call([ 'ffmpeg', '-i', audio_path, "-ar", str(sampling_rate), "-ac", "1", wav_path ]) audio = read(wav_path) audio = audio[1] wav_file = wav_path print(beatmap.Title) audio_ms = len(audio) / sampling_rate * 1000 redpoints = [] for tp in beatmap.TimingPoints: if tp[6] == 1: redpoints.append(tp) for index in range(len(redpoints) - 1): rp = redpoints[index] time = rp[0] tick = 0 while time + 30 < redpoints[index + 1][0]: times.append(time) tick_list.append(tick) time += rp[1] / 4 rp = redpoints[-1] time = rp[0] tick = 0 while time + 200 < audio_ms: times.append(time) tick_list.append(tick) time += rp[1] / 4 wav_data = read_wav_data(times, wav_file, snapsize=[0.25, 0.5, 1, 2, 4, 8, 16], fft_size=128) wav_data = np.swapaxes(wav_data, 0, 1) x = wav_data t = np.vstack(tick_list) return x.astype(np.float32, copy=False), times, t.astype(np.float32, copy=False)