- use native speech detector
This commit is contained in:
parent
48743574ad
commit
0bf8134feb
|
|
@ -36,8 +36,8 @@ class AgentConfig:
|
||||||
# Should the first task run immediately ?
|
# Should the first task run immediately ?
|
||||||
ForceRun = False
|
ForceRun = False
|
||||||
|
|
||||||
# Use silence eraser or not (speech detector is used in this case)
|
# Use external speech detector if needed
|
||||||
UseSilenceEraser = True
|
UseSpeechDetector = False
|
||||||
|
|
||||||
# Path to log file
|
# Path to log file
|
||||||
LogPath : Path = None
|
LogPath : Path = None
|
||||||
|
|
@ -90,7 +90,7 @@ class AgentConfig:
|
||||||
|
|
||||||
if 'speech_detector' in config:
|
if 'speech_detector' in config:
|
||||||
if config['speech_detector']:
|
if config['speech_detector']:
|
||||||
self.UseSilenceEraser = False
|
self.UseSpeechDetector = True
|
||||||
|
|
||||||
if 'audio' in config:
|
if 'audio' in config:
|
||||||
audio = config['audio']
|
audio = config['audio']
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,10 @@ def detect_degraded_signal(file_test: Path, file_reference: Path) -> SignalBound
|
||||||
# Seems some problem with recording, return zero boundaries
|
# Seems some problem with recording, return zero boundaries
|
||||||
return SignalBoundaries()
|
return SignalBoundaries()
|
||||||
|
|
||||||
r = bt_signal.find_reference_signal(file_test)
|
if CONFIG.UseSpeechDetector:
|
||||||
|
r = bt_signal.find_reference_signal_via_speechdetector(file_test)
|
||||||
|
else:
|
||||||
|
r = bt_signal.find_reference_signal(file_test)
|
||||||
|
|
||||||
if r.offset_start == 0.0 and is_caller:
|
if r.offset_start == 0.0 and is_caller:
|
||||||
r.offset_start = 5.0 # Skip ringing tones
|
r.offset_start = 5.0 # Skip ringing tones
|
||||||
|
|
@ -78,7 +81,10 @@ def detect_degraded_signal(file_test: Path, file_reference: Path) -> SignalBound
|
||||||
|
|
||||||
def detect_reference_signal(file_reference: Path) -> SignalBoundaries:
|
def detect_reference_signal(file_reference: Path) -> SignalBoundaries:
|
||||||
# Run silence eraser on reference file as well
|
# Run silence eraser on reference file as well
|
||||||
result = bt_signal.find_reference_signal(file_reference)
|
if CONFIG.UseSpeechDetector:
|
||||||
|
result = bt_signal.find_reference_signal_via_speechdetector(file_reference)
|
||||||
|
else:
|
||||||
|
result = bt_signal.find_reference_signal(file_reference)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,33 +3,22 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
|
from utils_types import SignalBoundaries
|
||||||
|
from utils_sevana import speech_detector
|
||||||
|
|
||||||
from pydub import silence, AudioSegment
|
from pydub import silence, AudioSegment
|
||||||
|
|
||||||
class SignalBoundaries:
|
SILENCE_DELTA = 16
|
||||||
# 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)}]'
|
|
||||||
|
|
||||||
|
|
||||||
def find_reference_signal(input_file: pathlib.Path, output_file: pathlib.Path = None, use_end_offset: bool = True) -> SignalBoundaries:
|
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))
|
myaudio = AudioSegment.from_wav(str(input_file))
|
||||||
dBFS = myaudio.dBFS
|
dBFS = myaudio.dBFS
|
||||||
|
|
||||||
# Find silence intervals
|
# 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
|
# 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)
|
# print(intervals)
|
||||||
|
|
||||||
|
|
@ -48,6 +37,12 @@ def find_reference_signal(input_file: pathlib.Path, output_file: pathlib.Path =
|
||||||
|
|
||||||
return SignalBoundaries()
|
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 __name__ == '__main__':
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print(f'Please specify input filename.')
|
print(f'Please specify input filename.')
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,25 @@ import utils
|
||||||
import json
|
import json
|
||||||
from crontab import CronTab
|
from crontab import CronTab
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Exit codes
|
# Exit codes
|
||||||
EXIT_OK = 0
|
EXIT_OK = 0
|
||||||
EXIT_ERROR = 1
|
EXIT_ERROR = 1
|
||||||
|
|
||||||
|
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)}]'
|
||||||
|
|
||||||
|
|
||||||
class Phone:
|
class Phone:
|
||||||
identifier: int = 0
|
identifier: int = 0
|
||||||
name: str = ""
|
name: str = ""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue