def make_god_song_01(complexity=None, amount=None, seed=None, save_path=None, scale=None): logger.info("Generating God song to {}".format(save_path)) if seed: random.seed(seed) if not complexity: complexity = random.randint(1, 4) if not scale: scale = random.choice(list(scale_dict)) # choose a random scale if not amount: amount = random.choice(list_beats) result = AudioSegment.silent(duration=0) random_list = random_with_complexity(random, scale, complexity, amount) # print(random_list) for beat in random_list: gen = Sine(beat["frequency"]) sine = gen.to_audio_segment(duration=beat["duration"]).apply_gain( beat["velocity"]) sine = sine.fade_in(beat["fade_in"]).fade_out(beat["fade_out"]) result += sine if save_path: result.export(save_path, format="mp3") return result
def makenoise(): print("Welcome to the generator. What would you like to generate?") command = input() if command == "sine": print("Which frequency?") frequency = input() sine = Sine(float(frequency)) out = sine.to_audio_segment(100) play(out)
if this_probability < switch_probability: which_tone = 1 - which_tone this_segment = songs[which_tone] if len(this_song) == 0: this_song += this_segment else: this_song = this_song.append(this_segment, crossfade=50) this_song.export(f"./stimuli/crossfade_switch-{str(switch_probability)}_chunk-{str(chunk_size)}_G3_C4_alternating.mp3", format="mp3", bitrate="192k") # # Generate sine waves with Pydub # In[15]: #create sine wave of given freq frequency = 440 sample_rate = 44100 # sample rate bit_depth = 16 # bit depth duration = 5000 # duration in millisec sine_wave = Sine(frequency, sample_rate=sample_rate, bit_depth=bit_depth) #Convert waveform to audio_segment for playback and export sine_segment = sine_wave.to_audio_segment(duration=duration) sine_segment