How to use the pydub.utils.make_chunks function in pydub

To help you get started, we’ve selected a few pydub 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 vishnu-ks / AudioNet / scripts / data_maker.py View on Github external
def makechunks(path):
    folders=glob.glob(path+'*')
    for folder in folders:
      waves = glob.glob(folder+'/'+ '*.wav')
      print ('w',waves)
      if len(waves) == 0:
          return 10
      for i in waves:
          w = i
          myaudio = AudioSegment.from_file(i, 'wav')
          chunk_length_ms = 20000
          chunks = make_chunks(myaudio, chunk_length_ms)
          print (chunks)
          for i, chunk in enumerate(chunks):
              chunk_name = w.split('.')[0] + "chunk{0}.wav".format(i)
              print (chunk_name)
              print ("exporting", chunk_name)
              chunk.export(folder+'/'+chunk_name, format="wav")
github skvoter / ymcli / loop_routins.py View on Github external
del player.stream_chunks[0]
            elif player.stream_chunks[0] == 'forward':
                if player.current_song_position + 5 > player.playlist[
                    player.current_song
                ].duration:
                    player.stream_chunks = []
                    player.stream_chunks.append('reset_time')
                    player.stream_chunks.append('next')
                elif player.current_song_position + 5 < len(
                    player.playlist[player.current_song].segment
                )/1000:
                    player.stream_chunks = []
                    seg = player.playlist[player.current_song].segment[
                        (player.current_song_position+5)*1000:]
                    player.current_song_position += 5
                    player.stream_chunks += make_chunks(seg, 1000)
                else:
                    del player.stream_chunks[0]
            elif player.stream_chunks[0] not in (
                'backward', 'forward', 'reset_time'
            ):
                stream.write(player.stream_chunks[0]._data)
                player.current_song_position += 1
                if player.stream_chunks[0] not in (
                    'next', 'forward', 'backward'
                ):
                    del player.stream_chunks[0]
                if player.current_song_position > (
                    player.playlist[player.current_song].duration/1000
                ):
                    player.stream_chunks = []
                    player.stream_chunks.append('reset_time')
github skvoter / ymcli / interfaces.py View on Github external
while self.state != 'stopped' and self.current_song is not None:
            song = self.playlist[self.current_song]
            self.stream_chunks.append('reset_time')
            with open(song.filename, 'rb') as r:
                if song.is_downloaded:
                    song.segment = AudioSegment.from_mp3(r)
                    self.stream_chunks += make_chunks(song.segment, 1000)
                    while self.current_song == self.playlist.index(song):
                        time.sleep(0.1)
                else:
                    while song.segment is None:
                        time.sleep(0.1)
                    seglen = len(song.segment)
                    oldlen = 0
                    if self.current_song == self.playlist.index(song):
                        self.stream_chunks += make_chunks(
                            song.segment[oldlen:seglen], 1000)
                    else:
                        continue
                    while self.current_song == self.playlist.index(song):
                        oldlen = seglen
                        seglen = len(song.segment)
                        if seglen > oldlen and \
                           self.current_song == self.playlist.index(song):
                            self.stream_chunks += make_chunks(
                                song.segment[oldlen:seglen], 1000)
                        time.sleep(0.1)
github mRokita / sMusic-core / smusicclient / player.py View on Github external
def __make_chunks(self):
        self.__segment = match_target_amplitude(AudioSegment.from_file(self.__path), -20)
        self.__chunks = make_chunks(self.__segment, 100)
github jiaaro / pydub / pydub / playback.py View on Github external
def _play_with_pyaudio(seg):
    import pyaudio

    p = pyaudio.PyAudio()
    stream = p.open(format=p.get_format_from_width(seg.sample_width),
                    channels=seg.channels,
                    rate=seg.frame_rate,
                    output=True)

    # break audio into half-second chunks (to allows keyboard interrupts)
    for chunk in make_chunks(seg, 500):
        stream.write(chunk._data)

    stream.stop_stream()
    stream.close()

    p.terminate()
github guysoft / AlarmBot / src / alarm.py View on Github external
stream = player.open(format=player.get_format_from_width(sound.sample_width),
                             channels=sound.channels,
                             rate=sound.frame_rate,
                             output=True)

        # PLAYBACK LOOP
        start = 0
        length = sound.duration_seconds
        volume = 100.0
        playchunk = sound[start*1000.0:(start+length)*1000.0] - (60 - (60 * (volume/100.0)))
        millisecondchunk = 50 / 1000.0

        while self.loop :
            self.time = start
            for chunks in make_chunks(playchunk, millisecondchunk*1000):
                self.time += millisecondchunk
                stream.write(chunks._data)
                if not self.loop:
                    break
                if self.time >= start+length:
                    break

        stream.close()
        player.terminate()
github skvoter / ymcli / interfaces.py View on Github external
handle_loop = Thread(target=handle_controls, args=(self,))
        stream_loop = Thread(target=start_stream, args=(self,))
        download_loop.daemon = True
        print_loop.daemon = True
        handle_loop.daemon = True
        print_loop.start()
        download_loop.start()
        stream_loop.start()
        handle_loop.start()
        while self.state != 'stopped' and self.current_song is not None:
            song = self.playlist[self.current_song]
            self.stream_chunks.append('reset_time')
            with open(song.filename, 'rb') as r:
                if song.is_downloaded:
                    song.segment = AudioSegment.from_mp3(r)
                    self.stream_chunks += make_chunks(song.segment, 1000)
                    while self.current_song == self.playlist.index(song):
                        time.sleep(0.1)
                else:
                    while song.segment is None:
                        time.sleep(0.1)
                    seglen = len(song.segment)
                    oldlen = 0
                    if self.current_song == self.playlist.index(song):
                        self.stream_chunks += make_chunks(
                            song.segment[oldlen:seglen], 1000)
                    else:
                        continue
                    while self.current_song == self.playlist.index(song):
                        oldlen = seglen
                        seglen = len(song.segment)
                        if seglen > oldlen and \