Advertisement
Tkap1

Untitled

Nov 6th, 2023
1,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. def beat_command(data):
  2.     from my_globals import default_frame_rate_index
  3.     sounds = [
  4.         handle_speed_and_channels(AudioSegment.from_file("sounds/hihat_closed.mp3", format="mp3"), default_frame_rate_index),
  5.         handle_speed_and_channels(AudioSegment.from_file("sounds/hihat_opened.mp3", format="mp3"), default_frame_rate_index),
  6.         handle_speed_and_channels(AudioSegment.from_file("sounds/clap.mp3", format="mp3"), default_frame_rate_index),
  7.         handle_speed_and_channels(AudioSegment.from_file("sounds/kick.mp3", format="mp3"), default_frame_rate_index),
  8.     ]
  9.     words = data.msg.split(" ")
  10.     if len(words) != 3: return
  11.     loop_count = utils.str_to_int(words[0])
  12.     if not loop_count: return
  13.     loop_count = utils.clamp(loop_count, 1, 5)
  14.     bpm = utils.str_to_int(words[1])
  15.     if not bpm: return
  16.     bpm = utils.clamp(bpm, 20, 1000)
  17.     beats_per_ms = bpm / 60 / 1000
  18.     beat_count = words[2].count("-") + 1
  19.     out_sound = AudioSegment.silent(1.0 / beats_per_ms * (beat_count * loop_count) * loop_count)
  20.     beats = words[2]
  21.  
  22.     position = 0
  23.     for loop_i in range(loop_count):
  24.         played = []
  25.         for char in beats:
  26.             if char == "-":
  27.                 played = []
  28.                 position += 1.0 / beats_per_ms
  29.             else:
  30.                 sound_index = utils.str_to_int(char)
  31.                 if sound_index == None:
  32.                     return
  33.                 if sound_index < 1 or sound_index > 4:
  34.                     return
  35.                 if sound_index in played:
  36.                     continue
  37.                 if len(played) >= 4:
  38.                     continue
  39.  
  40.                 played.append(sound_index)
  41.                 sound_to_add = sounds[sound_index - 1]
  42.                 out_sound = out_sound.overlay(sound_to_add, position=position)
  43.  
  44.         position += 1.0 / beats_per_ms
  45.  
  46.  
  47.     add_tts_to_queue(data.user, out_sound - 10)
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement