Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def beat_command(data):
- from my_globals import default_frame_rate_index
- sounds = [
- handle_speed_and_channels(AudioSegment.from_file("sounds/hihat_closed.mp3", format="mp3"), default_frame_rate_index),
- handle_speed_and_channels(AudioSegment.from_file("sounds/hihat_opened.mp3", format="mp3"), default_frame_rate_index),
- handle_speed_and_channels(AudioSegment.from_file("sounds/clap.mp3", format="mp3"), default_frame_rate_index),
- handle_speed_and_channels(AudioSegment.from_file("sounds/kick.mp3", format="mp3"), default_frame_rate_index),
- ]
- words = data.msg.split(" ")
- if len(words) != 3: return
- loop_count = utils.str_to_int(words[0])
- if not loop_count: return
- loop_count = utils.clamp(loop_count, 1, 5)
- bpm = utils.str_to_int(words[1])
- if not bpm: return
- bpm = utils.clamp(bpm, 20, 1000)
- beats_per_ms = bpm / 60 / 1000
- beat_count = words[2].count("-") + 1
- out_sound = AudioSegment.silent(1.0 / beats_per_ms * (beat_count * loop_count) * loop_count)
- beats = words[2]
- position = 0
- for loop_i in range(loop_count):
- played = []
- for char in beats:
- if char == "-":
- played = []
- position += 1.0 / beats_per_ms
- else:
- sound_index = utils.str_to_int(char)
- if sound_index == None:
- return
- if sound_index < 1 or sound_index > 4:
- return
- if sound_index in played:
- continue
- if len(played) >= 4:
- continue
- played.append(sound_index)
- sound_to_add = sounds[sound_index - 1]
- out_sound = out_sound.overlay(sound_to_add, position=position)
- position += 1.0 / beats_per_ms
- add_tts_to_queue(data.user, out_sound - 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement