add playing
This commit is contained in:
parent
cde05a556b
commit
d816eb9fca
1 changed files with 12 additions and 6 deletions
|
@ -290,27 +290,33 @@ class PydubRenderer(Renderer):
|
|||
return sorted([f for f in all_files if f.endswith(".mp3")])
|
||||
|
||||
def play(self, path: str, from_time: int) -> None:
|
||||
log.info(f"DebugRenderer: play({path}, {from_time})")
|
||||
self.start = int(time.time())
|
||||
log.info(f"PydubRenderer: play({path}, {from_time})")
|
||||
|
||||
self.audio_in = cast(AudioSegment, AudioSegment.from_mp3(path))
|
||||
self.audio_out = au.play_buffer(
|
||||
audio_data=self.audio_in,
|
||||
audio_data=self.audio_in[from_time*1000:],
|
||||
num_channels=self.audio_in.channels,
|
||||
bytes_per_sample=self.audio_in.sample_width,
|
||||
sample_rate = self.audio_in.frame_rate
|
||||
)
|
||||
self.audio_out
|
||||
self.start = int(time.time())
|
||||
self.offset = from_time
|
||||
self.audio_out.play()
|
||||
|
||||
def get_time(self) -> int:
|
||||
return int(time.time()) - self.start + self.offset
|
||||
|
||||
def stop(self) -> None:
|
||||
log.info("DebugRenderer: stop()")
|
||||
log.info("PydubRenderer: stop()")
|
||||
if self.is_playing():
|
||||
self.audio_out.stop()
|
||||
self.audio_out = None
|
||||
self.audio_in = None
|
||||
self.start = 0
|
||||
self.offset = 0
|
||||
|
||||
def is_playing(self) -> bool:
|
||||
return False
|
||||
return self.audio_out is not None and self.audio_out.is_playing()
|
||||
|
||||
|
||||
def main(media_path: str, renderer_type: str) -> None:
|
||||
|
|
Loading…
Reference in a new issue