Acoustics API

Classes

class polyglotdb.acoustics.classes.Track[source]

Track class to contain, select, and manage TimePoint objects

Attributes
pointsiterable of TimePoint

Time points with values of the acoustic track

add(point)[source]

Add a TimePoint to the track

Parameters
pointTimePoint

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
beginfloat

Begin time for the slice

endfloat

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
timefloat

The time of the time point

valuesdict

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
namestr

Name of the measure

valueobject

Measure value

has_value(name)[source]

Check whether a time point contains a named measure

Parameters
namestr

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
columnsiterable

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
pointpolyglotdb.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_contextCorpusContext

The CorpusContext object of the corpus

annotation_typestr, optional

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

subsetstr, optional

Specify a subset to use for generating segments

file_typestr, 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_contextpolyglot.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_contextpolyglot.corpus.context.CorpusContext

The CorpusContext object of the corpus

file_typestr, 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_contextCorpusContext

corpus context to use

vowel_labelstr, optional

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

call_backcallable

call back function, optional

stop_checkcallable

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_contextpolyglot.corpus.context.CorpusContext

The CorpusContext object of the corpus.

call_backcallable

Information about callback.

stop_checkstring

Information about stop check.

vowel_labelstr

The subset of phones to analyze.

duration_thresholdfloat, 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_contextCorpusContext

The CorpusContext object of the corpus.

vowel_labelstr

The subset of phones to analyze.

duration_thresholdfloat, optional

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

num_iterationsint, optional

How many times the algorithm should iterate before returning values.

output_tracksbool, 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_metadatadict

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_contextpolyglot.corpus.context.CorpusContext

The CorpusContext object of the corpus.

genderstr

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

sourcestr

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_functionPartial 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_contextCorpusContext

The CorpusContext object of the corpus.

min_formantsint

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

max_formantsint

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

Returns
formant_functionPartial 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_contextCorpusContext

The CorpusContext object of the corpus.

min_formantsint

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

max_formantsint

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

Returns
formant_functionPartial 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_contextCorpusContext

corpus context to use

sourcestr

Source program to use (only praat available)

call_backcallable

call back function, optional

stop_checkfunction

stop check function, optional

multiprocessingbool

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_contextCorpusContext

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_contextAudioContext
sourcestr

Program to use for analyzing pitch, either praat or reaper

algorithmstr

Algorithm to use, base, gendered, or speaker_adjusted

absolute_min_pitchint

Absolute pitch floor

absolute_max_pitchint

Absolute pitch ceiling

adjusted_octavesint

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

stop_checkcallable

Function to check whether processing should stop early

call_backcallable

Function to report progress

multiprocessingbool

Flag whether to use multiprocessing or threading

Returns

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_contextAudioContext
classifierstr

Path to an AutoVOT classifier model

stop_labelstr

Label of subset to analyze

vot_minint

Minimum VOT in ms

vot_maxint

Maximum VOT in ms

window_minint

Window minimum in ms

window_maxint

Window maximum in Ms

overwrite_edited:

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

call_backcallable

call back function, optional

stop_checkcallable

stop check function, optional

multiprocessingbool

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_contextCorpusContext

corpus context to use

phone_classstr

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

subsetstr, optional

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

annotation_typestr

the type of annotation that the analysis will go over

script_pathstr

full path to the praat script

duration_thresholdfloat

Minimum duration of segments to be analyzed

file_typestr

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

argumentslist

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

call_backcallable

call back function, optional

stop_checkcallable

stop check function, optional

multiprocessingbool

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_pathstring

full path to praat/praatcon

script_path: string

full path to the script

argumentslist

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