adding support for pitch and tempo commands on torchlight through rubberband
This commit is contained in:
parent
f420bfc7ed
commit
dc8b4badd0
@ -303,8 +303,8 @@ class AudioClip():
|
|||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.Logger.info("~AudioClip()")
|
self.Logger.info("~AudioClip()")
|
||||||
|
|
||||||
def Play(self, seconds = None, *args):
|
def Play(self, seconds = None, rubberband = None, *args):
|
||||||
return self.AudioPlayer.PlayURI(self.URI, seconds, *args)
|
return self.AudioPlayer.PlayURI(self.URI, seconds, rubberband = rubberband, *args)
|
||||||
|
|
||||||
def Stop(self):
|
def Stop(self):
|
||||||
return self.AudioPlayer.Stop()
|
return self.AudioPlayer.Stop()
|
||||||
|
@ -525,6 +525,25 @@ class VoiceCommands(BaseCommand):
|
|||||||
elif Level < 2:
|
elif Level < 2:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
rubberband = []
|
||||||
|
try:
|
||||||
|
for msg in message[1].split(" "): #checking if pitch= or tempo= is specified
|
||||||
|
if "tempo=" in msg:
|
||||||
|
tempo = float(msg.split("tempo=",1)[1])
|
||||||
|
if tempo < 0.0:
|
||||||
|
tempo = 0.01
|
||||||
|
if tempo > 20:
|
||||||
|
tempo = 20
|
||||||
|
rubberband.append(f"rubberband=tempo={tempo}")
|
||||||
|
elif "pitch=" in msg:
|
||||||
|
pitch = float(msg.split("pitch=",1)[1])
|
||||||
|
if pitch < 0.0:
|
||||||
|
pitch = 0.1
|
||||||
|
if pitch > 99:
|
||||||
|
pitch = 99
|
||||||
|
rubberband.append(f"rubberband=pitch={pitch}")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
if message[0] == "!random":
|
if message[0] == "!random":
|
||||||
Trigger = self.random.choice(list(self.VoiceTriggers.values()))
|
Trigger = self.random.choice(list(self.VoiceTriggers.values()))
|
||||||
if isinstance(Trigger, list):
|
if isinstance(Trigger, list):
|
||||||
@ -535,7 +554,7 @@ class VoiceCommands(BaseCommand):
|
|||||||
Sounds = self.VoiceTriggers[message[0]]
|
Sounds = self.VoiceTriggers[message[0]]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Num = int(message[1])
|
Num = int(message[1].split(" ")[0])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
Num = None
|
Num = None
|
||||||
|
|
||||||
@ -545,7 +564,7 @@ class VoiceCommands(BaseCommand):
|
|||||||
|
|
||||||
elif message[1]:
|
elif message[1]:
|
||||||
searching = message[1].startswith('?')
|
searching = message[1].startswith('?')
|
||||||
search = message[1][1:] if searching else message[1]
|
search = message[1][1:] if searching else message[1].split(" ")[0]
|
||||||
Sound = None
|
Sound = None
|
||||||
names = []
|
names = []
|
||||||
matches = []
|
matches = []
|
||||||
@ -590,7 +609,7 @@ class VoiceCommands(BaseCommand):
|
|||||||
if not AudioClip:
|
if not AudioClip:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
return AudioClip.Play()
|
return AudioClip.Play(rubberband = rubberband)
|
||||||
|
|
||||||
|
|
||||||
class YouTube(BaseCommand):
|
class YouTube(BaseCommand):
|
||||||
@ -717,7 +736,7 @@ class DECTalk(BaseCommand):
|
|||||||
def __init__(self, torchlight):
|
def __init__(self, torchlight):
|
||||||
super().__init__(torchlight)
|
super().__init__(torchlight)
|
||||||
self.Triggers = ["!dec"]
|
self.Triggers = ["!dec"]
|
||||||
self.Level = 6
|
self.Level = 5
|
||||||
|
|
||||||
async def Say(self, player, message):
|
async def Say(self, player, message):
|
||||||
message = "[:phoneme on]" + message
|
message = "[:phoneme on]" + message
|
||||||
@ -907,3 +926,5 @@ class Reload(BaseCommand):
|
|||||||
async def _func(self, message, player):
|
async def _func(self, message, player):
|
||||||
self.Logger.debug(sys._getframe().f_code.co_name + ' ' + str(message))
|
self.Logger.debug(sys._getframe().f_code.co_name + ' ' + str(message))
|
||||||
self.Torchlight().Reload()
|
self.Torchlight().Reload()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
@ -57,16 +57,22 @@ class FFmpegAudioPlayer():
|
|||||||
self.Master.Logger.debug("~FFmpegAudioPlayer()")
|
self.Master.Logger.debug("~FFmpegAudioPlayer()")
|
||||||
self.Stop()
|
self.Stop()
|
||||||
|
|
||||||
def PlayURI(self, uri, position, *args):
|
def PlayURI(self, uri, position, rubberband = None, *args):
|
||||||
if position:
|
if position:
|
||||||
PosStr = str(datetime.timedelta(seconds = position))
|
PosStr = str(datetime.timedelta(seconds = position))
|
||||||
Command = ["/usr/bin/ffmpeg", "-ss", PosStr, "-i", uri, "-acodec", "pcm_s16le", "-ac", "1", "-ar", str(int(self.SampleRate)), "-f", "s16le", "-vn", *args, "-"]
|
Command = ["/usr/bin/ffmpeg", "-ss", PosStr, "-i", uri, "-acodec", "pcm_s16le", "-ac", "1", "-ar", str(int(self.SampleRate)), "-f", "s16le", "-vn", *args]
|
||||||
else:
|
else:
|
||||||
Command = ["/usr/bin/ffmpeg", "-i", uri, "-acodec", "pcm_s16le", "-ac", "1", "-ar", str(int(self.SampleRate)), "-f", "s16le", "-vn", *args, "-"]
|
Command = ["/usr/bin/ffmpeg", "-i", uri, "-acodec", "pcm_s16le", "-ac", "1", "-ar", str(int(self.SampleRate)), "-f", "s16le", "-vn", *args]
|
||||||
|
|
||||||
print(Command)
|
|
||||||
|
|
||||||
self.Playing = True
|
self.Playing = True
|
||||||
|
if rubberband:
|
||||||
|
Command += ["-filter:a"]
|
||||||
|
rubberCommand = ""
|
||||||
|
for rubber in rubberband:
|
||||||
|
rubberCommand += rubber + ", "
|
||||||
|
rubberCommand = rubberCommand[:-2]
|
||||||
|
Command += [rubberCommand]
|
||||||
|
Command += ["-"]
|
||||||
asyncio.ensure_future(self._stream_subprocess(Command))
|
asyncio.ensure_future(self._stream_subprocess(Command))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user