Skip to content

Commit

Permalink
3.0.5 (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcauliffe authored Apr 12, 2024
1 parent 7611ddd commit 610bad4
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 10 deletions.
18 changes: 18 additions & 0 deletions bin/mfa_update
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python

import os
import shutil
import subprocess
from importlib.util import find_spec

anchor_found = find_spec("anchor") is not None

conda_path = shutil.which("conda")
mamba_path = shutil.which("mamba")
if mamba_path is None:
print("No mamba found, installing first...")
subprocess.call([conda_path, "install", "-c", "conda-forge", "-y", "mamba"], env=os.environ)
package_list = ["montreal-forced-aligner", "kalpy", "kaldi=*=cpu*"]
if anchor_found:
package_list.append("anchor-annotator")
subprocess.call([mamba_path, "update", "-c", "conda-forge", "-y"] + package_list, env=os.environ)
7 changes: 7 additions & 0 deletions docs/source/changelog/changelog_3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
3.0 Changelog
*************

3.0.5
=====

- Added :code:`mfa_update` command to better sync changes across dependencies
- Updated how calculated properties are loaded to fix crashes in Anchor
- Change when alignments are analyzed in training

3.0.4
=====

Expand Down
6 changes: 5 additions & 1 deletion docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ General installation
Updating Montreal Forced Aligner
--------------------------------

To install the latest version, please run either :code:`conda update -c conda-forge montreal-forced-aligner --update-deps` or :code:`mamba update -c conda-forge montreal-forced-aligner --update-deps` if you have mamba installed.
To install the latest version, please run either :code:`conda update -c conda-forge montreal-forced-aligner kalpy kaldi=*=cpu* --update-deps` or :code:`mamba update -c conda-forge montreal-forced-aligner kalpy kaldi=*=cpu* --update-deps` if you have mamba installed.

.. versionadded:: 3.0.5

MFA version 3.0.5 onward has a helper utility for updating to new versions. Run :code:`mfa_update` to fetch the latest versions of MFA, Kalpy, and Kaldi.

Installing SpeechBrain
----------------------
Expand Down
2 changes: 1 addition & 1 deletion montreal_forced_aligner/acoustic_modeling/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ def export_files(
Flag for including the original text of the corpus files as a tier
"""
self.align()
self.analyze_alignments()
super(TrainableAligner, self).export_files(
output_directory, output_format, include_original_text
)
Expand Down Expand Up @@ -708,6 +707,7 @@ def align(self) -> None:
{"done": True}
)
session.commit()
self.analyze_alignments()
except Exception as e:
with self.session() as session:
session.query(CorpusWorkflow).filter(CorpusWorkflow.id == wf.id).update(
Expand Down
57 changes: 49 additions & 8 deletions montreal_forced_aligner/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from praatio import textgrid
from praatio.utilities.constants import Interval
from sqlalchemy import Boolean, Column, DateTime, Enum, Float, ForeignKey, Integer, String
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.ext.orderinglist import ordering_list
from sqlalchemy.orm import Bundle, declarative_base, joinedload, relationship

Expand Down Expand Up @@ -1393,7 +1394,9 @@ class Utterance(MfaSqlBase):
id = Column(Integer, primary_key=True, autoincrement=True)
begin = Column(Float, nullable=False, index=True)
end = Column(Float, nullable=False)
duration = Column(Float, sqlalchemy.Computed('"end" - "begin"'), index=True)
_duration = sqlalchemy.orm.deferred(
Column("duration", Float, sqlalchemy.Computed('"end" - "begin"'), index=True)
)
channel = Column(Integer, nullable=False)
num_frames = Column(Integer)
text = Column(String)
Expand All @@ -1418,11 +1421,13 @@ class Utterance(MfaSqlBase):
xvector = Column(Vector(config.XVECTOR_DIMENSION), nullable=True)
file_id = Column(Integer, ForeignKey("file.id"), index=True, nullable=False)
speaker_id = Column(Integer, ForeignKey("speaker.id"), index=True, nullable=False)
kaldi_id = Column(
String,
sqlalchemy.Computed("CAST(speaker_id AS text)|| '-' ||CAST(id AS text)"),
unique=True,
index=True,
_kaldi_id = sqlalchemy.orm.deferred(
Column(
"kaldi_id",
String,
sqlalchemy.Computed("CAST(speaker_id AS text)|| '-' ||CAST(id AS text)"),
unique=True,
)
)
job_id = Column(Integer, ForeignKey("job.id"), index=True, nullable=True)
file = relationship("File", back_populates="utterances", cascade_backrefs=False)
Expand All @@ -1449,6 +1454,22 @@ class Utterance(MfaSqlBase):
),
)

@hybrid_property
def duration(self) -> float:
return self.end - self.begin

@duration.expression
def duration(cls):
return cls._duration

@hybrid_property
def kaldi_id(self) -> str:
return f"{self.speaker_id}-{self.id}"

@kaldi_id.expression
def kaldi_id(cls):
return cls._kaldi_id

def __repr__(self) -> str:
"""String representation of the utterance object"""
return f"<Utterance in {self.file_name} by {self.speaker_name} from {self.begin} to {self.end}>"
Expand Down Expand Up @@ -1751,7 +1772,9 @@ class PhoneInterval(MfaSqlBase):
begin = Column(Float, nullable=False, index=True)
end = Column(Float, nullable=False)
phone_goodness = Column(Float, nullable=True)
duration = Column(Float, sqlalchemy.Computed('"end" - "begin"'))
_duration = sqlalchemy.orm.deferred(
Column("duration", Float, sqlalchemy.Computed('"end" - "begin"'))
)

phone_id = Column(
Integer, ForeignKey("phone.id", ondelete="CASCADE"), index=True, nullable=False
Expand All @@ -1777,6 +1800,14 @@ class PhoneInterval(MfaSqlBase):
sqlalchemy.Index("phone_utterance_workflow_index", "utterance_id", "workflow_id"),
)

@hybrid_property
def duration(self) -> float:
return self.end - self.begin

@duration.expression
def duration(cls):
return cls._duration

def __repr__(self):
return f"<PhoneInterval {self.phone.kaldi_label} ({self.workflow.workflow_type}) from {self.begin}-{self.end} for utterance {self.utterance_id}>"

Expand Down Expand Up @@ -1859,7 +1890,9 @@ class WordInterval(MfaSqlBase):
id = Column(Integer, primary_key=True, autoincrement=True)
begin = Column(Float, nullable=False, index=True)
end = Column(Float, nullable=False)
duration = Column(Float, sqlalchemy.Computed('"end" - "begin"'))
_duration = sqlalchemy.orm.deferred(
Column("duration", Float, sqlalchemy.Computed('"end" - "begin"'))
)

utterance_id = Column(
Integer, ForeignKey("utterance.id", ondelete="CASCADE"), index=True, nullable=False
Expand Down Expand Up @@ -1891,6 +1924,14 @@ class WordInterval(MfaSqlBase):
sqlalchemy.Index("word_utterance_workflow_index", "utterance_id", "workflow_id"),
)

@hybrid_property
def duration(self) -> float:
return self.end - self.begin

@duration.expression
def duration(cls):
return cls._duration

@classmethod
def from_ctm(
self, interval: CtmInterval, utterance: Utterance, workflow_id: int
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ exclude = tests
[options.entry_points]
console_scripts =
mfa = montreal_forced_aligner.command_line.mfa:mfa_cli
scripts =
bin/mfa_update

[options.extras_require]
anchor =
Expand Down

0 comments on commit 610bad4

Please sign in to comment.