Exemplo n.º 1
0
    def loadSounds(self):
        # Load the sounds, if enabled
        if sounds_enabled:
            self.sounds = {}

            snd_control_beep_file = open("snd/control_beep.wav", "rb")
            self.sounds['snd_control_beep'] = audiocore.WaveFile(
                snd_control_beep_file)

            snd_engage_beep_file = open("snd/engage_beep.wav", "rb")
            self.sounds['snd_engage_beep'] = audiocore.WaveFile(
                snd_engage_beep_file)

            snd_startup_file = open("snd/tricorder_short.wav", "rb")
            self.sounds['snd_startup'] = audiocore.WaveFile(snd_startup_file)
Exemplo n.º 2
0
    def __work(self, sl):
        while(True):
            if not self.queue.empty():
                #Hay valores en la cola
                if (not self.manualMode or (self.manualMode and self.playNext)):
                    #O estamos en modo automático, o en manual con playNext activado
                    audioFile = self.queue.get()
                    logging.info("Audio Thread: Playing audio - "+str(audioFile))

                    #Required for CircuitPlayground Express
                    #speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
                    #speaker_enable.switch_to_output(value=True)

                    data = open("./audio_files/data_smoke_test_LDC93S1_pcms16le_1_16000.wav", "rb")
                    wav = audiocore.WaveFile(data)
                    a = audiopwmio.PWMAudioOut(board.SPEAKER)

                    a.play(wav)
                    while a.playing:
                        pass
                    
                    logging.info("Audio Thread: Finished audio - "+str(audioFile))
                    logging.info ("Audio Thread: Current queue size - "+str(self.queue.qsize()))
                    self.queue.task_done()
                    self.playNext = False
                else:
                    #Estamos en modo manual sin playNext activado
                    logging.info("Audio Thread: Awaiting manual trigger")
            else:
                logging.info("Audio Thread: Empty Queue")

        logging.info("Audio Thread: Sleeping for - "+str(sl)+"ms")
        time.sleep(sl)
    def play_file(self, file_name):
        """ Play a .wav file using the onboard speaker.

        :param file_name: The name of your .wav file in quotation marks including .wav

        .. image :: ../docs/_static/speaker.jpg
          :alt: Onboard speaker

        To use with the Circuit Playground Express or Bluefruit:

        .. code-block:: python

             from adafruit_circuitplayground import cp

             while True:
                 if cp.button_a:
                     cp.play_file("laugh.wav")
                 elif cp.button_b:
                     cp.play_file("rimshot.wav")
        """
        # Play a specified file.
        self.stop_tone()
        self._speaker_enable.value = True
        with self._audio_out(board.SPEAKER) as audio:  # pylint: disable=not-callable
            wavefile = audiocore.WaveFile(open(file_name, "rb"))
            audio.play(wavefile)
            while audio.playing:
                pass
        self._speaker_enable.value = False
def play_wave(filename):
    wave_file = open(filename, "rb")
    wave = audiocore.WaveFile(wave_file)
    audio.play(wave)
    while audio.playing:
        pass
    wave_file.close()
Exemplo n.º 5
0
    def play_file(self, file_name):
        """ Play a .wav file using the onboard speaker.

        :param file_name: The name of your .wav file in quotation marks including .wav

        .. code-block:: python

             from Kevin_CircuitPythonBadge.Badge import Badge

             while True:
                 if Badge.left_button:
                     Badge.play_file("laugh.wav")
                 elif Badge.right_button:
                     Badge.play_file("rimshot.wav")
        """
        # Play a specified file.
        self.stop_tone()
        self._speaker_enable.value = True
        if sys.implementation.version[0] >= 3:
            with audioio.AudioOut(board.SPEAKER) as audio:
                wavefile = audiocore.WaveFile(open(file_name, "rb"))
                audio.play(wavefile)
                while audio.playing:
                    pass
        else:
            raise NotImplementedError(
                "Please use CircuitPython 3.0 or higher.")
        self._speaker_enable.value = False
Exemplo n.º 6
0
 def play(self, audio_file, loop=False):
     import audiocore
     if self.muted:
         return
     self.stop()
     wave = audiocore.WaveFile(audio_file, self.buffer)
     self.audio.play(wave, loop=loop)
Exemplo n.º 7
0
def play_waves(file_num):
    wave_file = open(wave_files[file_num], "rb")  # open a wav file
    wave = audiocore.WaveFile(wave_file)
    audio.play(wave)  # play the wave file
    while audio.playing:  # allow the wav to finish playing
        pass
    wave_file.close()  # close the wav file
Exemplo n.º 8
0
def fireOverheat():
    wave_file = open(WAV_OVERHEAT, "rb")
    wave = audiocore.WaveFile(wave_file)
    audio.play(wave)
    while audio.playing:
        pass
    wave_file.close()
Exemplo n.º 9
0
    def play_file(self, file_name):
        """ Play a .wav file using the onboard speaker.

        :param file_name: The name of your .wav file in quotation marks including .wav

        .. image :: ../docs/_static/speaker.jpg
          :alt: Onboard speaker

        .. code-block:: python

             from adafruit_circuitplayground.express import cpx

             while True:
                 if cpx.button_a:
                     cpx.play_file("laugh.wav")
                 elif cpx.button_b:
                     cpx.play_file("rimshot.wav")
        """
        # Play a specified file.
        self.stop_tone()
        self._speaker_enable.value = True
        if sys.implementation.version[0] >= 3:
            with audioio.AudioOut(board.SPEAKER) as audio:
                wavefile = audiocore.WaveFile(open(file_name, "rb"))
                audio.play(wavefile)
                while audio.playing:
                    pass
        else:
            raise NotImplementedError(
                "Please use CircuitPython 3.0 or higher.")
        self._speaker_enable.value = False
Exemplo n.º 10
0
def play_audio(wavfile):
    f = open(wavfile, "rb")
    wav = audiocore.WaveFile(f)
    a.play(wav)
    while a.playing:
        pass
    f.close()
    gc.collect()
Exemplo n.º 11
0
 def playAudio(self, file_name):
     self.speaker_enable.value = True
     with audioio.AudioOut(board.SPEAKER) as audio:
         wavefile = audiocore.WaveFile(open(file_name, "rb"))
         audio.play(wavefile)
         while audio.playing:
             pass
     self.speaker_enable.value = False
Exemplo n.º 12
0
def play_file(wavfile):
    wavfile = "/numbers/" + wavfile
    print("Playing", wavfile)
    with open(wavfile, "rb") as f:
        wav = audiocore.WaveFile(f)
        aout.play(wav)
        while aout.playing:
            pass
Exemplo n.º 13
0
def reload():
    global shotCounter
    shotCounter = 0
    wave_file = open(WAV_RELOAD, "rb")
    wave = audiocore.WaveFile(wave_file)
    audio.play(wave)
    while audio.playing:
        pass
Exemplo n.º 14
0
def load_wav(name):
    """
    Load a WAV audio file into RAM.
    @param name: partial file name string, complete name will be built on
                 this, e.g. passing 'foo' will load file 'foo.wav'.
    @return WAV buffer that can be passed to play_wav() below.
    """
    return audiocore.WaveFile(open(name + '.wav', 'rb'))
def play_file(wavfile):
    print("Playing", wavfile)
    with open(wavfile, "rb") as f:
        wav = audiocore.WaveFile(f)
        AUDIO.play(wav)
        while AUDIO.playing:
            LED.duty_cycle = random.randint(5000, 30000)
            time.sleep(0.1)
    LED.duty_cycle = 65535
Exemplo n.º 16
0
def play_file(filename):
    global audio_file  # pylint: disable=global-statement
    if gc_audio.playing:
        gc_audio.stop()
    if audio_file:
        audio_file.close()
    audio_file = open(filename, "rb")
    wav = audiocore.WaveFile(audio_file)
    gc_audio.play(wav)
Exemplo n.º 17
0
def play_file(wavfile):
    with open(wavfile, "rb") as file:
        wavf = audiocore.WaveFile(file)
        a.play(wavf)
        while a.playing:
            servos[1].angle = MOUTH_START
            time.sleep(.2)
            servos[1].angle = MOUTH_END
            time.sleep(.2)
Exemplo n.º 18
0
def play_file(playname):
    print("Playing File " + playname)
    wave_file = open(playname, "rb")
    with audiocore.WaveFile(wave_file) as wave:
        with audioio.AudioOut(board.A0) as audio:
            audio.play(wave)
            while audio.playing:
                simpleCircle(.02)
    print("finished")
Exemplo n.º 19
0
def play_file(audio_filename):
    global audio_file  # pylint: disable=global-statement
    if myaudio.playing:
        myaudio.stop()
    if audio_file:
        audio_file.close()
    audio_file = open("/sounds/"+audio_filename, "rb")
    wav = audiocore.WaveFile(audio_file)
    print("Playing "+audio_filename+".")
    myaudio.play(wav)
Exemplo n.º 20
0
def play_file(wavfile):
    print("Playing scream!")
    with open(wavfile, "rb") as f:
        wav = audiocore.WaveFile(f)
        a.play(wav)
        while a.playing:
            head_servo.angle = 60
            time.sleep(.01)
            head_servo.angle = 120
            time.sleep(.01)
Exemplo n.º 21
0
def play_audio():
    #open the file
    wave_file = open("liftoff.wav", "rb")
    #play the file
    with audiocore.WaveFile(wave_file) as wave:
        with audioio.AudioOut(board.A0) as audio:
            audio.play(wave)
            #wait until audio is done
            while audio.playing:
                pass
 def note_on(self, key, velocity):
     fname = self._samples[key]
     if fname is not None:
         f = open(SAMPLE_FOLDER+fname, 'rb')
         wav = audiocore.WaveFile(f)
         voice = self._find_usable_voice_for(key)
         if voice is not None:
             voice['key'] = key
             voice['file'] = f
             self._mixer.play(wav, voice=voice['voice'], loop=False)
Exemplo n.º 23
0
def play_file(wavfile):
    print("Playing", wavfile)
    with open(wavfile, "rb") as f:
        wav = audiocore.WaveFile(f)
        a.play(wav)
        while a.playing:  # turn servos, motors, etc. during playback
            mouth_servo.angle = MOUTH_END
            time.sleep(0.15)
            mouth_servo.angle = MOUTH_START
            time.sleep(0.15)
Exemplo n.º 24
0
def play_file(wavfile):
    print("Playing", wavfile)
    with open(wavfile, "rb") as f:
        wav = audiocore.WaveFile(f)
        a.play(wav)
        while a.playing:
            my_servo.angle = MOUTH_END
            time.sleep(.15)
            my_servo.angle = MOUTH_START
            time.sleep(.15)
Exemplo n.º 25
0
def fire():
    global shotCounter
    shotCounter += 1
    wave_file = open(WAV_FIRE, "rb")
    wave = audiocore.WaveFile(wave_file)
    audio.play(wave)
    while audio.playing:
        pixels[1] = NEOPIX_COLOUR_BARREL
    pixels[1] = NEOPIX_OFF
    time.sleep(1)
def play_wave():
    wave_file = open("hiss01.wav", "rb")  # open a wav file
    wave = audiocore.WaveFile(wave_file)
    audio.play(wave)  # play the wave file
    led.value = True
    servo_release()
    print('Motion detected!')
    while audio.playing:  # turn on LED, turn servo
        pass
    wave_file.close()  # close the wav file
Exemplo n.º 27
0
 def play(self, audio_file, loop=False):
     """
     Start playing an open file ``audio_file``. If ``loop`` is ``True``,
     repeat until stopped. This function doesn't block, the sound is
     played in the background.
     """
     if self.muted:
         return
     self.stop()
     wave = audiocore.WaveFile(audio_file, self.buffer)
     self.audio.play(wave, loop=loop)
Exemplo n.º 28
0
def audio_test3():
    #with audioio.AudioOut(board.SPEAKER) as audio:
    amp_enable.value = True
    #wavefile = audiocore.WaveFile(open("cha-ching.wav", "rb"))
    wavefile = audiocore.WaveFile(
        open(wav_file_options[randint(0,
                                      len(wav_file_options) - 1)], "rb"))
    audio.play(wavefile)
    while audio.playing:
        pass
    amp_enable.value = False
Exemplo n.º 29
0
def play_wave(wavname):


    data = open(wavname, "rb")
    wav = audiocore.WaveFile(data)


    print("playing")
    a.play(wav)
    while a.playing:
        pass
    print("stopped")
Exemplo n.º 30
0
def play_file(wav_file_name):
    try:
        data = open(wav_file_name, "rb")
        wav = audiocore.WaveFile(data)
        a.play(wav)
        print("Playing: " + wav_file_name)
        while a.playing:
            pass
        a.stop()
    except OSError:  # Error thrown if it finds a .bmp file with no corresponding .wav file
        # Print the name of the .bmp file with no corresponding .wav file
        print("No corresponding wav file:", slideshow.current_image_name)