Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update search for noise dictionary to match all SoundSwallower versions (fixes #183) #184

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions readalongs/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
# Set the minimum FFT size (no longer necessary since
# SoundSwallower 0.2, but we keep this here for compatibility with
# old versions in case we need to debug things)
frame_points = int(asr_config["samprate"] * asr_config["wlen"])
frame_points = int(asr_config["samprate"] * asr_config["wlen"]) # type: ignore
fft_size = 1
while fft_size < frame_points:
fft_size = fft_size << 1
Expand All @@ -298,19 +298,31 @@
Set[str]: Set of noise words from noisedict, or a default set
if it could not be found.
"""
try:
noisewords = set()
acoustic_model = asr_config["hmm"]
with open(
os.path.join(acoustic_model, "noisedict"), "rt", encoding="utf-8"
) as dictfh:
for line in dictfh:
if line.startswith("##") or line.startswith(";;"):
continue
noisewords.add(line.strip().split()[0])
except FileNotFoundError:

def load_noisedict(fdict):
try:
with open(fdict, "rt", encoding="utf-8") as dictfh:
noisewords = set()
for line in dictfh:
if line.startswith("##") or line.startswith(";;"):
continue

Check warning on line 308 in readalongs/align.py

View check run for this annotation

Codecov / codecov/patch

readalongs/align.py#L308

Added line #L308 was not covered by tests
noisewords.add(line.strip().split()[0])
return noisewords
except FileNotFoundError:
return None

Check warning on line 312 in readalongs/align.py

View check run for this annotation

Codecov / codecov/patch

readalongs/align.py#L311-L312

Added lines #L311 - L312 were not covered by tests

fdict: str = asr_config["fdict"] # type: ignore
acoustic_model: str = asr_config["hmm"] # type: ignore
noisewords = None
if fdict is not None: # pragma: no cover
noisewords = load_noisedict(fdict)
if noisewords is None:
noisewords = load_noisedict(os.path.join(acoustic_model, "noisedict.txt"))
if noisewords is None: # pragma: no cover
noisewords = load_noisedict(os.path.join(acoustic_model, "noisedict"))
if noisewords is None: # pragma: no cover
LOGGER.warning("Could not find noisedict, using defaults")
noisewords = {"<sil>", "[NOISE]"}
noisewords = {"<sil>", "<s>", "</s>", "[NOISE]"}

return noisewords

Expand Down Expand Up @@ -624,7 +636,7 @@
# millisecond intervals. For audio segments, the ms slice assumption is hard-coded
# all over, while frame_size is used to convert segment boundaries returned by
# soundswallower, which are indexes in frames, into durations in seconds.
frame_size = 1.0 / asr_config["frate"]
frame_size = 1.0 / asr_config["frate"] # type: ignore

# Get list of words to ignore in aligner output
noisewords = read_noisedict(asr_config)
Expand Down