|
@@ -1,6 +1,29 @@
|
|
|
+import typing
|
|
|
+
|
|
|
import scipy.io.wavfile
|
|
|
|
|
|
|
|
|
+def trim_where(
|
|
|
+
|
|
|
+ sequence: typing.Sequence,
|
|
|
+ condition: typing.Sequence[bool],
|
|
|
+) -> typing.Sequence:
|
|
|
+ start = 0
|
|
|
+ for item_condition in condition:
|
|
|
+ if item_condition:
|
|
|
+ start += 1
|
|
|
+ else:
|
|
|
+ break
|
|
|
+ stop = len(sequence)
|
|
|
+ assert stop == len(condition)
|
|
|
+ for item_condition in condition[::-1]:
|
|
|
+ if item_condition:
|
|
|
+ stop -= 1
|
|
|
+ else:
|
|
|
+ break
|
|
|
+ return sequence[start:stop]
|
|
|
+
|
|
|
+
|
|
|
def wavfile_read_mono(path):
|
|
|
|
|
|
rate, data = scipy.io.wavfile.read(path)
|