How to use playsound - 10 common examples

To help you get started, we’ve selected a few playsound examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dark-archerx / Traffic-Signs-and-Object-Detection / main.py View on Github external
display.blit(advt, (970, 350))

       # print(lang)

        pygame.display.update()
        if closestLabel:
          if(closestLabel in vehicles and closestDist < 17*10):
            if(lang==0):
              playsound("./sounds/vehicle_ahead_hi.mp3")
            elif(lang==1):
              playsound("./sounds/vehicle_ahead_en.mp3")
            elif(lang==2):
              playsound("./sounds/vehicle_ahead_mh.mp3")
            elif(lang==3):
              playsound("./sounds/vehicle_ahead_bn.mp3")
          else:
            if(closestLabel=="stop sign"):
              if(lang==0):
                playsound("./sounds/stop_hi.mp3")
              elif(lang==1):
                playsound("./sounds/stop_en.mp3")
              elif(lang==2):
                playsound("./sounds/stop_mh.mp3")
              elif(lang==3):
                playsound("./sounds/stop_bn.mp3")
            elif(closestLabel=="turn left"):
              if(lang==0):
                playsound("./sounds/tl_hi.mp3")
              elif(lang==1):
                playsound("./sounds/tl_en.mp3")
              elif(lang==2):
github matthiaaas / otto-assistant / linux / ai.py View on Github external
def say(text):
        # this is an alternative solution and is NOT fast
        # on RPi aiy.tts
        # on Windows win32com speech engine
        # on Mac standard preinstalled 'say'
        # on Linux gTTS: bad and slow
        AI.log("(!) long delay because of bad TTS solution: much better on Windows, RPi, Mac")
        # tts
        with NamedTemporaryFile() as f:
            # google server request
            tts = gTTS(text=text, lang=AI.settings.language.split("-")[0])
            # save received file
            tts.save(f.name+".mp3")
            # play
            playsound.playsound(f.name+".mp3")
github tmercswims / tmerc-cogs / playsound / playsound.py View on Github external
cf.error("Please only add one sound at a time."))
            return

        url = ""
        filename = ""
        if attach:
            a = attach[0]
            url = a["url"]
            filename = a["filename"]
        elif link:
            url = "".join(link)
            filename = os.path.basename(
                "_".join(url.split()).replace("%20", "_"))
        else:
            await self.bot.reply(
                cf.error("You must provide either a Discord attachment or a"
                         " direct link to a sound."))
            return

        filepath = os.path.join(self.sound_base, server.id, filename)

        if os.path.splitext(filename)[0] in self.list_sounds(server.id):
            await self.bot.reply(
                cf.error("A sound with that filename already exists."
                         " Please change the filename and try again."))
            return

        async with aiohttp.get(url) as new_sound:
            f = open(filepath, "wb")
            f.write(await new_sound.read())
            f.close()
github tmercswims / tmerc-cogs / playsound / playsound.py View on Github external
filename = a["filename"]
        elif link:
            url = "".join(link)
            filename = os.path.basename(
                "_".join(url.split()).replace("%20", "_"))
        else:
            await self.bot.reply(
                cf.error("You must provide either a Discord attachment or a"
                         " direct link to a sound."))
            return

        filepath = os.path.join(self.sound_base, server.id, filename)

        if os.path.splitext(filename)[0] in self.list_sounds(server.id):
            await self.bot.reply(
                cf.error("A sound with that filename already exists."
                         " Please change the filename and try again."))
            return

        async with aiohttp.get(url) as new_sound:
            f = open(filepath, "wb")
            f.write(await new_sound.read())
            f.close()

        self.settings[server.id][
            os.path.splitext(filename)[0]] = {"volume": default_volume}
        dataIO.save_json(self.settings_path, self.settings)

        await self.bot.reply(
            cf.info("Sound {} added.".format(os.path.splitext(filename)[0])))
github tmercswims / tmerc-cogs / playsound / playsound.py View on Github external
await self.bot.type()

        server = ctx.message.server

        if server.id not in os.listdir(self.sound_base):
            os.makedirs(os.path.join(self.sound_base, server.id))

        if server.id not in self.settings:
            self.settings[server.id] = {}
            dataIO.save_json(self.settings_path, self.settings)

        attach = ctx.message.attachments
        if len(attach) > 1 or (attach and link):
            await self.bot.reply(
                cf.error("Please only add one sound at a time."))
            return

        url = ""
        filename = ""
        if attach:
            a = attach[0]
            url = a["url"]
            filename = a["filename"]
        elif link:
            url = "".join(link)
            filename = os.path.basename(
                "_".join(url.split()).replace("%20", "_"))
        else:
            await self.bot.reply(
                cf.error("You must provide either a Discord attachment or a"
                         " direct link to a sound."))
github tmercswims / tmerc-cogs / playsound / playsound.py View on Github external
async def sound_play(self, ctx: commands.Context, p: str, vol: int):
        server = ctx.message.server
        if not ctx.message.author.voice_channel:
            await self.bot.reply(
                cf.warning("You need to join a voice channel first."))
            return

        if self.voice_channel_full(ctx.message.author.voice_channel):
            return

        if not ctx.message.channel.is_private:
            if self.voice_connected(server):
                if server.id not in self.audio_players:
                    await self.sound_init(ctx, p, vol)
                    self.audio_players[server.id].start()
                    await self.wait_for_disconnect(server)
                else:
                    if self.audio_players[server.id].is_playing():
                        self.audio_players[server.id].stop()
                    await self.sound_init(ctx, p, vol)
                    self.audio_players[server.id].start()
github richmondu / libfaceid / libfaceid / speech_synthesizer.py View on Github external
def playaudio(self, filename, block):
        if self._option == 0:
            from playsound import playsound # lazy loading
            #print("playsound")
            playsound(filename, block)
        else:
            pass
github bradtraversy / alexis_speech_assistant / main.py View on Github external
def speak(audio_string):
    tts = gTTS(text=audio_string, lang='en') # text to speech(voice)
    r = random.randint(1,20000000)
    audio_file = 'audio' + str(r) + '.mp3'
    tts.save(audio_file) # save as mp3
    playsound.playsound(audio_file) # play the audio file
    print(f"kiri: {audio_string}") # print what app said
    os.remove(audio_file) # remove audio file