Skip to content

Commit

Permalink
Add deprecation for SoX and Praat methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbrickhouse committed Oct 18, 2022
1 parent 4a9612f commit 023a7d8
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions fave/extractFormants.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@
from bisect import bisect_left

import parselmouth

from deprecated.sphinx import deprecated
from deprecated.sphinx import versionadded
from deprecated.sphinx import versionchanged
import numpy as np

from tqdm import tqdm

import fave
Expand All @@ -92,6 +93,7 @@
from fave.extract.remeasure import remeasure
from fave.extract.mahalanobis import mahalanobis

SCRIPTS_HOME = pkg_resources.resource_filename('fave','praatScripts')
os.chdir(os.getcwd())

uncertain = re.compile(r"\(\(([\*\+]?['\w]+\-?)\)\)")
Expand Down Expand Up @@ -446,6 +448,28 @@ def checkLocation(file):
print("ERROR: Could not locate %s" % file)
sys.exit()

@deprecated(version="2.1.0",reason="External speech software will not be supported.")
def checkSpeechSoftware(speechSoftware):
"""checks that either Praat or ESPS is available as a speech analysis program"""

if speechSoftware in ['ESPS', 'esps']:
if os.name == 'nt':
print("ERROR: ESPS was specified as the speech analysis program, but this option is not yet compatible with Windows")
sys.exit()
if not programExists('formant'):
print("ERROR: ESPS was specified as the speech analysis program, but the command 'formant' is not in your path")
sys.exit()
else:
return 'esps'
elif speechSoftware in ['praat', 'Praat']:
if not ((PRAATPATH and programExists(speechSoftware, PRAATPATH)) or (os.name == 'posix' and programExists(speechSoftware)) or (os.name == 'nt' and programExists('praatcon.exe'))):
print("ERROR: Praat was specified as the speech analysis program, but the command 'praat' ('praatcon' for Windows) is not in your path")
sys.exit()
else:
return speechSoftware
else:
print("ERROR: unsupported speech analysis software %s" % speechSoftware)
sys.exit()

def checkTextGridFile(tgFile):
"""checks whether a TextGrid file exists and has the correct file format"""
Expand Down Expand Up @@ -539,6 +563,21 @@ def detectMonophthong(formants, measurementPoint, index):

return glide

@deprecated(version="2.1",reason="Parselmouth migration replaces SoX")
def extractPortion(wavFile, vowelWavFile, beg, end, soundEditor):
"""extracts a single vowel (or any other part) from the main sound file"""

if soundEditor == 'sox': # this is the default setting, since it's faster
# force output format because there have been issues with some sound
# files where Praat could not read the extracted portion
os.system(os.path.join(SOXPATH, 'sox') + ' ' + wavFile + ' -t wavpcm ' +
os.path.join(SCRIPTS_HOME, vowelWavFile) + ' trim ' + str(beg) + ' ' + str(end - beg))
elif soundEditor == 'praat':
os.system(os.path.join(PRAATPATH, PRAATNAME) + ' ' + SCRIPTS_HOME + '/extractSegment.praat ' +
os.path.join(os.path.pardir, wavFile) + ' ' + vowelWavFile + ' ' + str(beg) + ' ' + str(end))
else:
pass

def faav(phone, formants, times, intensity):
"""returns the time of measurement according to the FAAV guidelines"""

Expand Down

0 comments on commit 023a7d8

Please sign in to comment.