def run(self):
# Open an audio segment
sound = AudioSegment.from_file(self.filepath)
player = pyaudio.PyAudio()
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()
评论列表
文章目录