Acoustics API

Classes

class polyglotdb.acoustics.classes.Track[source]

Track class to contain, select, and manage TimePoint objects

Attributes:
points : iterable of TimePoint

Time points with values of the acoustic track

add(point)[source]

Add a TimePoint to the track

Parameters:
point : TimePoint

Time point to add

items()[source]

Generator for returning tuples of the time point and values

Returns:
generator

Tuples of time points and values

keys()[source]

Get a list of all keys for TimePoints that the Track has

Returns:
list

All keys on TimePoint objects

slice(begin, end)[source]

Create a slice of the acoustic track between two times

Parameters:
begin : float

Begin time for the slice

end : float

End time for the slice

Returns:
Track

Track constructed from just the time points in the specified time

times()[source]

Get a list of all time points in the track

Returns:
list

Sorted time points

class polyglotdb.acoustics.classes.TimePoint(time)[source]

Class for handling acoustic measurements at a specific time point

Attributes:
time : float

The time of the time point

values : dict

Dictionary of acoustic measures for the given time point

add_value(name, value)[source]

Add a new named measure and value to the TimePoint

Parameters:
name : str

Name of the measure

value : object

Measure value

has_value(name)[source]

Check whether a time point contains a named measure

Parameters:
name : str

Name of the measure

Returns:
bool

True if name is in values and has a value

select_values(columns)[source]

Generate a dictionary of only the specified measurement names

Parameters:
columns : iterable

Iterable of measurement names to include

Returns:
dict

Subset of values if their name is in the specified columns

update(point)[source]

Update values in this time point from another TimePoint

Parameters:
point : polyglotdb.acoustics.classes.TimePoint

TimePoint to get values from

Segments

polyglotdb.acoustics.segments.generate_segments(corpus_context, annotation_type='utterance', subset=None, file_type='vowel', duration_threshold=0.001, padding=0, fetch_subannotations=False)[source]

Generate segment vectors for an annotation type, to be used as input to analyze_file_segments.

Parameters:
corpus_context : CorpusContext

The CorpusContext object of the corpus

annotation_type : str, optional

The type of annotation to use in generating segments, defaults to utterance

subset : str, optional

Specify a subset to use for generating segments

file_type : str, optional

One of ‘low_freq’, ‘vowel’, or ‘consonant’, specifies the type of audio file to use

duration_threshold: float, optional

Segments with length shorter than this value (in seconds) will not be included

Returns:
SegmentMapping

Object containing segments to be analyzed

polyglotdb.acoustics.segments.generate_vowel_segments(corpus_context, duration_threshold=None, padding=0, vowel_label='vowel')[source]

Generate segment vectors for each vowel, to be used as input to analyze_file_segments.

Parameters:
corpus_context : polyglot.corpus.context.CorpusContext

The CorpusContext object of the corpus

duration_threshold: float, optional

Segments with length shorter than this value (in seconds) will not be included

Returns:
SegmentMapping

Object containing vowel segments to be analyzed

polyglotdb.acoustics.segments.generate_utterance_segments(corpus_context, file_type='vowel', duration_threshold=None, padding=0)[source]

Generate segment vectors for each utterance, to be used as input to analyze_file_segments.

Parameters:
corpus_context : polyglot.corpus.context.CorpusContext

The CorpusContext object of the corpus

file_type : str, optional

One of ‘low_freq’, ‘vowel’, or ‘consonant’, specifies the type of audio file to use

duration_threshold: float, optional

Segments with length shorter than this value (in seconds) will not be included

Returns:
SegmentMapping

Object containing utterance segments to be analyzed

Formants

polyglotdb.acoustics.formants.base.analyze_formant_tracks(corpus_context, vowel_label=None, source='praat', call_back=None, stop_check=None, multiprocessing=True)[source]

Analyze formants of an entire utterance, and save the resulting formant tracks into the database.

Parameters:
corpus_context : CorpusContext

corpus context to use

vowel_label : str, optional

Optional subset of phones to compute tracks over. If None, then tracks over utterances are computed.

call_back : callable

call back function, optional

stop_check : callable

stop check function, optional

polyglotdb.acoustics.formants.base.analyze_formant_points(corpus_context, call_back=None, stop_check=None, vowel_label='vowel', duration_threshold=None, multiprocessing=True)[source]

First pass of the algorithm; generates prototypes.

Parameters:
corpus_context : polyglot.corpus.context.CorpusContext

The CorpusContext object of the corpus.

call_back : callable

Information about callback.

stop_check : string

Information about stop check.

vowel_label : str

The subset of phones to analyze.

duration_threshold : float, optional

Segments with length shorter than this value (in milliseconds) will not be analyzed.

Returns:
dict

Track data

polyglotdb.acoustics.formants.refined.analyze_formant_points_refinement(corpus_context, vowel_label='vowel', duration_threshold=0, num_iterations=1, call_back=None, stop_check=None, vowel_prototypes_path='', drop_formant=False, multiprocessing=True, output_tracks=False)[source]

Extracts F1, F2, F3 and B1, B2, B3.

Parameters:
corpus_context : CorpusContext

The CorpusContext object of the corpus.

vowel_label : str

The subset of phones to analyze.

duration_threshold : float, optional

Segments with length shorter than this value (in milliseconds) will not be analyzed.

num_iterations : int, optional

How many times the algorithm should iterate before returning values.

output_tracks : bool, optional

Whether to save only the formant values as a point at 0.33 if false or have a track over the entire vowel duration if true.

Returns:
prototype_metadata : dict

Means of F1, F2, F3, B1, B2, B3 and covariance matrices per vowel class.

Conch function generators

polyglotdb.acoustics.formants.helper.generate_base_formants_function(corpus_context, gender=None, source='praat')[source]
Parameters:
corpus_context : polyglot.corpus.context.CorpusContext

The CorpusContext object of the corpus.

gender : str

The gender to use for the function, if “M”(male) then the max frequency is 5000 Hz, otherwise 5500

source : str

The source of the function, if it is “praat” then the formants will be calculated with Praat over each segment otherwise it will simply be tracks

Returns
——-
formant_function : Partial function object

The function used to call Praat.

polyglotdb.acoustics.formants.helper.generate_formants_point_function(corpus_context, gender=None)[source]

Generates a function used to call Praat to measure formants and bandwidths with variable num_formants.

Parameters:
corpus_context : CorpusContext

The CorpusContext object of the corpus.

min_formants : int

The minimum number of formants to measure with on subsequent passes (default is 4).

max_formants : int

The maximum number of formants to measure with on subsequent passes (default is 7).

Returns:
formant_function : Partial function object

The function used to call Praat.

polyglotdb.acoustics.formants.helper.generate_variable_formants_point_function(corpus_context, min_formants, max_formants)[source]

Generates a function used to call Praat to measure formants and bandwidths with variable num_formants. This specific function returns a single point per formant at a third of the way through the segment

Parameters:
corpus_context : CorpusContext

The CorpusContext object of the corpus.

min_formants : int

The minimum number of formants to measure with on subsequent passes (default is 4).

max_formants : int

The maximum number of formants to measure with on subsequent passes (default is 7).

Returns:
formant_function : Partial function object

The function used to call Praat.

Intensity

polyglotdb.acoustics.intensity.analyze_intensity(corpus_context, source='praat', call_back=None, stop_check=None, multiprocessing=True)[source]

Analyze intensity of an entire utterance, and save the resulting intensity tracks into the database.

Parameters:
corpus_context : CorpusContext

corpus context to use

source : str

Source program to use (only praat available)

call_back : callable

call back function, optional

stop_check : function

stop check function, optional

multiprocessing : bool

Flag to use multiprocessing rather than threading

Conch function generators

polyglotdb.acoustics.intensity.generate_base_intensity_function(corpus_context)[source]

Generate an Intensity function from Conch

Parameters:
corpus_context : CorpusContext

CorpusContext to use for getting path to Praat (if not on the system path)

Returns:
PraatSegmentIntensityTrackFunction

Intensity analysis function

Pitch

polyglotdb.acoustics.pitch.base.analyze_pitch(corpus_context, source='praat', algorithm='base', call_back=None, absolute_min_pitch=50, absolute_max_pitch=500, adjusted_octaves=1, stop_check=None, multiprocessing=True)[source]
Parameters:
corpus_context : AudioContext
source : str

Program to use for analyzing pitch, either praat or reaper

algorithm : str

Algorithm to use, base, gendered, or speaker_adjusted

absolute_min_pitch : int

Absolute pitch floor

absolute_max_pitch : int

Absolute pitch ceiling

adjusted_octaves : int

How many octaves around the speaker’s mean pitch to set the speaker adjusted pitch floor and ceiling

stop_check : callable

Function to check whether processing should stop early

call_back : callable

Function to report progress

multiprocessing : bool

Flag whether to use multiprocessing or threading

Conch function generators

polyglotdb.acoustics.pitch.helper.generate_pitch_function(algorithm, min_pitch, max_pitch, path=None, kwargs=None)[source]

VOT

polyglotdb.acoustics.vot.base.analyze_vot(corpus_context, classifier, stop_label='stops', vot_min=5, vot_max=100, window_min=-30, window_max=30, overwrite_edited=False, call_back=None, stop_check=None, multiprocessing=False)[source]

Analyze VOT for stops using a pretrained AutoVOT classifier.

Parameters:
corpus_context : AudioContext
classifier : str

Path to an AutoVOT classifier model

stop_label : str

Label of subset to analyze

vot_min : int

Minimum VOT in ms

vot_max : int

Maximum VOT in ms

window_min : int

Window minimum in ms

window_max : int

Window maximum in Ms

overwrite_edited:

Whether to updated VOTs which have the property, edited set to True

call_back : callable

call back function, optional

stop_check : callable

stop check function, optional

multiprocessing : bool

Flag to use multiprocessing, otherwise will use threading

Other

polyglotdb.acoustics.other.analyze_track_script(corpus_context, acoustic_name, properties, script_path, duration_threshold=0.01, phone_class=None, arguments=None, call_back=None, file_type='consonant', stop_check=None, multiprocessing=True)[source]
polyglotdb.acoustics.other.analyze_script(corpus_context, phone_class=None, subset=None, annotation_type=None, script_path=None, duration_threshold=0.01, arguments=None, call_back=None, file_type='consonant', stop_check=None, multiprocessing=True)[source]

Perform acoustic analysis of phones using an input praat script.

Saves the measurement results from the praat script into the database under the same names as the Praat output columns Praat script requirements:

  • the only input is the full path to the sound file containing (only) the phone
  • the script prints the output to the Praat Info window in two rows (i.e. two lines).
  • the first row is a space-separated list of measurement names: these are the names that will be saved into the database
  • the second row is a space-separated list of the value for each measurement
Parameters:
corpus_context : CorpusContext

corpus context to use

phone_class : str

DEPRECATED, the name of an already encoded subset of phones on which the analysis will be run

subset : str, optional

the name of an already encoded subset of an annotation type, on which the analysis will be run

annotation_type : str

the type of annotation that the analysis will go over

script_path : str

full path to the praat script

duration_threshold : float

Minimum duration of segments to be analyzed

file_type : str

File type to use for the script (consonant = 16kHz sample rate, vowel = 11kHz, low_freq = 1200 Hz)

arguments : list

a list containing any arguments to the praat script (currently not working)

call_back : callable

call back function, optional

stop_check : callable

stop check function, optional

multiprocessing : bool

Flag to use multiprocessing, otherwise will use threading

Conch function generators

polyglotdb.acoustics.other.generate_praat_script_function(praat_path, script_path, arguments=None)[source]

Generate a partial function that calls the praat script specified. (used as input to analyze_file_segments)

Parameters:
praat_path : string

full path to praat/praatcon

script_path: string

full path to the script

arguments : list

a list containing any arguments to the praat script, optional (currently not implemented)

Returns:
function

the partial function which applies the Praat script to a phone and returns the script output