58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
#!/usr/bin/python3
|
|
|
|
import sys
|
|
import os
|
|
import pathlib
|
|
from utils_types import SignalBoundaries
|
|
from utils_sevana import speech_detector
|
|
|
|
# from pydub import silence, AudioSegment
|
|
|
|
SILENCE_DELTA = 16
|
|
|
|
# def find_reference_signal(input_file: pathlib.Path, output_file: pathlib.Path = None, use_end_offset: bool = True) -> SignalBoundaries:
|
|
# myaudio = AudioSegment.from_wav(str(input_file))
|
|
# dBFS = myaudio.dBFS
|
|
|
|
# # Find silence intervals
|
|
# intervals = silence.detect_nonsilent(myaudio, min_silence_len=1000, silence_thresh=dBFS-SILENCE_DELTA, seek_step=50)
|
|
|
|
# # Translate to seconds
|
|
# intervals = [((start/1000),(stop/1000)) for start,stop in intervals] # in sec
|
|
|
|
# # print(intervals)
|
|
|
|
# # Example of intervals: [(5.4, 6.4), (18.7, 37.05)]
|
|
# for p in intervals:
|
|
# if p[1] - p[0] > 17:
|
|
# bounds = SignalBoundaries(offset_start=p[0], offset_finish=p[1])
|
|
# if output_file is not None:
|
|
# signal = myaudio[bounds.offset_start * 1000 : bounds.offset_finish * 1000]
|
|
# signal.export(str(output_file), format='wav', parameters=['-ar', '44100', '-sample_fmt', 's16'])
|
|
|
|
# if use_end_offset:
|
|
# bounds.offset_finish = myaudio.duration_seconds - bounds.offset_finish
|
|
|
|
# return bounds
|
|
|
|
# return SignalBoundaries()
|
|
|
|
|
|
def find_reference_signal_via_speechdetector(input_file: pathlib.Path) -> SignalBoundaries:
|
|
bounds = speech_detector(str(input_file))
|
|
r = SignalBoundaries(bounds[0], bounds[1])
|
|
return bounds
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) < 2:
|
|
print(f'Please specify input filename.')
|
|
exit(os.EX_NOINPUT)
|
|
|
|
# Output file
|
|
output_file = pathlib.Path(sys.argv[2]) if len(sys.argv) > 2 else None
|
|
|
|
# Input file
|
|
input_file = sys.argv[1]
|
|
bounds: SignalBoundaries = find_reference_signal(pathlib.Path(input_file), output_file)
|
|
print (bounds)
|