Skip to content

Commit

Permalink
Merge pull request #33 from Forced-Alignment-and-Vowel-Extraction/dev
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
JoFrhwld authored Nov 8, 2024
2 parents 25711cb + 206b22a commit 4099ce1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "new-fave"
version = "1.0.0"
version = "1.0.1"
description = "New Vowel Extraction Suite"
authors = ["JoFrhwld <[email protected]>"]
license = "GPLv3"
Expand Down
2 changes: 1 addition & 1 deletion src/new_fave/patterns/fave_audio_textgrid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fasttrackpy import process_audio_textgrid
from fasttrackpy.utils.safely import safely
from new_fave.utils.safely import safely
from aligned_textgrid import AlignedTextGrid
from fave_recode.fave_recode import (run_recode,
get_rules,
Expand Down
31 changes: 20 additions & 11 deletions src/new_fave/utils/fasttrack_config.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import yaml
from pathlib import Path
from fasttrackpy import Smoother
from new_fave.utils.local_resources import fave_fasttrack

def read_fasttrack(config:str|Path)->dict:
with Path(fave_fasttrack).open('r') as c:
ft_dict = yaml.safe_load(c)

config_dict = dict()
if config:
if type(config) is str:
config = Path(config)

with config.open('r') as c:
config_dict = yaml.safe_load(c)

for key in config_dict:
if key in ft_dict:
ft_dict[key] = config_dict[key]

def read_fasttrack(config = str|Path)->dict:
if type(config) is str:
config = Path(config)

with config.open('r') as c:
config_dict = yaml.safe_load(c)

smoother = Smoother()
if "smoother" in config_dict:
smoother = Smoother(**config_dict["smoother"])
if "smoother" in ft_dict:
smoother = Smoother(**ft_dict["smoother"])

config_dict["smoother"] = smoother
ft_dict["smoother"] = smoother

return config_dict
return ft_dict
25 changes: 25 additions & 0 deletions src/new_fave/utils/safely.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import warnings
from typing import Callable
def safely(
message: str = f"There was a problem a function's application."
):
"""
A decorator for more graceful failing.
If the decorated function raises an exception,
it will return `None`.
Args:
message (str, optional):
A warning message in the case of an exception.
Defaults to `f"There was a problem a function's application."`.
"""
def decorator(func:Callable):
def safe_func(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
warnings.warn(message + "\n" + str(e))
return None
return safe_func
return decorator

0 comments on commit 4099ce1

Please sign in to comment.