async def get_stream_player(voice_client: discord.VoiceClient): ydl.download([arguments], ) file = re.sub("[a-z]+?$", "opus", filename) def after(): asyncio.ensure_future(stream_player.notify()) return voice_client.create_ffmpeg_player(file, use_avconv=True, after=after)
async def _alert(self, bot: commands.Bot, channel: discord.Channel, vc: discord.VoiceClient): ## voice alert len_pattern = len(self.pattern) to_speak = self.pattern[self.__used % len_pattern] to_speak_name = to_speak['name'] to_speak_speech = to_speak['say'] voice_file = './cache/' + self.lang + '_' + to_speak_name if not os.path.isfile(voice_file): tts = gTTS(text=to_speak_speech, lang=self.lang) tts.save(voice_file) print('Created voice') player = vc.create_ffmpeg_player(voice_file) player.start() await asyncio.sleep(5) player.stop()
def enqueue(self, url: str, voice: discord.VoiceClient): song_info = self.get_dl(url) full_song = { "url": url, "voice": voice, "title": song_info['title'], "duration": song_info.get('duration') } if self.playing: print('Song is currently playing. Adding to queue...') self.playlist.put_nowait(full_song) else: print('Queue is empty. Starting song...') self.current_song = full_song self.player = voice.create_ffmpeg_player(song_info['url'], after=self.when_finished) self.playing = True self.player.start() return full_song