added feature for playing sounds backwards

This commit is contained in:
2024-10-15 19:04:18 +02:00
parent 5c9de31835
commit fad8daf05d
3 changed files with 178 additions and 120 deletions
@@ -8,6 +8,33 @@ import math
from .Utils import Utils, DataHolder
import traceback
def get_birtate(message):
bitrate = []
try:
for msg in message[1].split(" "): #checking if
if "bitrate=" in msg:
bitrate = int(msg.split("bitrate=",1)[1])
if bitrate < 0.0:
bitrate = 0.01
if bitrate > 2000:
bitrate = 20
bitrate.append(f"bitrate=tempo={bitrate}")
except Exception:
pass
return bitrate
def get_backwards(message):
backwards = None
try:
for msg in message[1].split(" "): #checking if pitch= or tempo= is specified
if "backward=" in msg.lower():
backwards = True
elif "backwards=" in msg.lower():
backwards = True
except Exception:
pass
return backwards
def get_rubberBand(message):
rubberband = []
try:
@@ -548,6 +575,8 @@ class VoiceCommands(BaseCommand):
return 0
rubberband = get_rubberBand(message)
backwards = get_backwards(message)
bitrate = get_birtate(message)
if message[0] == "!random":
Trigger = self.random.choice(list(self.VoiceTriggers.values()))
@@ -614,7 +643,7 @@ class VoiceCommands(BaseCommand):
if not AudioClip:
return 1
return AudioClip.Play(rubberband = rubberband)
return AudioClip.Play(rubberband = rubberband, bitrate = bitrate, backwards = backwards)
class YouTube(BaseCommand):
@@ -647,7 +676,9 @@ class YouTube(BaseCommand):
#turning the string into a list where get_rubberband just picks the second element to search in
dline = ['', line.split(" ", 1)[1]]
rubberband = get_rubberBand(dline)
return AudioClip.Play(Time, rubberband = rubberband)
backwards = get_backwards(dline)
bitrate = get_birtate(dline)
return AudioClip.Play(Time, rubberband = rubberband, bitrate = bitrate, backwards = backwards)
class YouTubeSearch(BaseCommand):
import json
@@ -693,7 +724,9 @@ class YouTubeSearch(BaseCommand):
#turning the string into a list where get_rubberband just picks the second element to search in
dline = ['', line.split(" ", 1)[1]]
rubberband = get_rubberBand(dline)
return AudioClip.Play(Time, rubberband = rubberband)
backwards = get_backwards(dline)
bitrate = get_birtate(dline)
return AudioClip.Play(Time, rubberband = rubberband, bitrate = bitrate, backwards = backwards)
class Say(BaseCommand):
@@ -721,9 +754,17 @@ class Say(BaseCommand):
try:
dline = ['', message.split(" ", 1)[1]]
rubberband = get_rubberBand(dline)
backwards = get_backwards(dline)
except Exception:
rubberband = None
if AudioClip.Play(rubberband = rubberband):
backwards = None
try:
dline = ['', message.split(" ", 1)[1]]
bitrate = get_birtate(dline)
except Exception:
bitrate = None
if AudioClip.Play(rubberband = rubberband, bitrate = bitrate, backwards = backwards):
AudioClip.AudioPlayer.AddCallback("Stop", lambda: os.unlink(TempFile.name))
return 0
else: