- use native speech detector
This commit is contained in:
@@ -3,33 +3,22 @@
|
||||
import sys
|
||||
import os
|
||||
import pathlib
|
||||
from utils_types import SignalBoundaries
|
||||
from utils_sevana import speech_detector
|
||||
|
||||
from pydub import silence, AudioSegment
|
||||
|
||||
class SignalBoundaries:
|
||||
# Offset from start (in seconds)
|
||||
offset_start: float
|
||||
|
||||
# Offset from finish (in seconds)
|
||||
offset_finish: float
|
||||
|
||||
def __init__(self, offset_start = 0.0, offset_finish = 0.0) -> None:
|
||||
self.offset_start = offset_start
|
||||
self.offset_finish = offset_finish
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'[offset_start: {round(self.offset_start, 3)}, offset_finish : {round(self.offset_finish, 3)}]'
|
||||
|
||||
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-17, seek_step=50)
|
||||
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
|
||||
intervals = [((start/1000),(stop/1000)) for start,stop in intervals] # in sec
|
||||
|
||||
# print(intervals)
|
||||
|
||||
@@ -48,6 +37,12 @@ def find_reference_signal(input_file: pathlib.Path, output_file: pathlib.Path =
|
||||
|
||||
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.')
|
||||
|
||||
Reference in New Issue
Block a user