|
@@ -1,6 +1,29 @@
|
|
|
+import typing
|
|
|
+
|
|
|
import scipy.io.wavfile
|
|
|
|
|
|
|
|
|
+def trim_where(
|
|
|
+ # https://docs.python.org/3.8/library/collections.abc.html#collections-abstract-base-classes
|
|
|
+ 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):
|
|
|
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.read.html
|
|
|
rate, data = scipy.io.wavfile.read(path)
|