join-partial-lines.py

This commit is contained in:
2022-09-27 06:00:34 +00:00
parent 8dffb5633d
commit 9a71ef0ada
2 changed files with 118 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
from imports import *
import numpy as np
def arg(num, usage, default=None):
val = ''
@@ -30,7 +31,7 @@ class AudioCutter:
self.wav = wave.open(f)
self.nchannels, self.sampwidth, self.framerate, self.nframes, self.comptype, self.compname = self.wav.getparams()
_, self.data = wavfile.read(wav_file)
self.rate, self.data = wavfile.read(wav_file)
# Accumulate new sound data cut from the original, along with new related json data
self.new_data = self.data[0:1]
@@ -58,6 +59,12 @@ class AudioCutter:
self.current_sec += length
self.new_json_info[tag] = info
def add_silence(self, seconds):
nframes = int(seconds * self.rate)
shape = self.new_data.shape
shape = (nframes,) + shape[1:]
self.new_data = vstack((self.new_data, np.zeros(shape, self.new_data.dtype)))
def play_audio(self, start, end):
audio, _ = self.audio_and_length(start, end)
play_buffer(audio, self.nchannels, self.sampwidth, self.framerate)