INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
Synthesize text into a WAVE file. Return a tuple consisting of: 1. the handler of the generated audio file 2. the path of the generated audio file 3. the list of anchors, that is, a list of floats each representing the start time of the corresponding text fragment...
def _synthesize(self, text_file): """ Synthesize text into a WAVE file. Return a tuple consisting of: 1. the handler of the generated audio file 2. the path of the generated audio file 3. the list of anchors, that is, a list of floats each representing the st...
Align two AudioFileMFCC objects, representing WAVE files. Return a list of boundary indices.
def _align_waves(self, real_wave_mfcc, synt_wave_mfcc, synt_anchors): """ Align two AudioFileMFCC objects, representing WAVE files. Return a list of boundary indices. """ self.log(u"Creating DTWAligner...") aligner = DTWAligner( real_wave_mfcc, ...
Adjust boundaries as requested by the user. Return the computed time map, that is, a list of pairs ``[start_time, end_time]``, of length equal to number of fragments + 2, where the two extra elements are for the HEAD (first) and TAIL (last).
def _adjust_boundaries(self, boundary_indices, text_file, real_wave_mfcc, sync_root, force_aba_auto=False, leaf_level=False): """ Adjust boundaries as requested by the user. Return the computed time map, that is, a list of pairs ``[start_time, end_time]``, of length equal to num...
Append trivial tree, made by one HEAD, one sync map fragment for each element of ``text_file``, and one TAIL. This function is called if either ``text_file`` has only one element, or if ``sync_root.value`` is an interval with zero length (i.e., ``sync_root.value.begin == sync_ro...
def _append_trivial_tree(self, text_file, sync_root): """ Append trivial tree, made by one HEAD, one sync map fragment for each element of ``text_file``, and one TAIL. This function is called if either ``text_file`` has only one element, or if ``sync_root.value`` is an i...
If requested, check that the computed sync map is consistent. Then, add it to the Task.
def _create_sync_map(self, sync_root): """ If requested, check that the computed sync map is consistent. Then, add it to the Task. """ sync_map = SyncMap(tree=sync_root, rconf=self.rconf, logger=self.logger) if self.rconf.safety_checks: self.log(u"Running sani...
Detect the interval of the audio file containing the fragments in the text file. Return the audio interval as a tuple of two :class:`~aeneas.exacttiming.TimeValue` objects, representing the begin and end time, in seconds, with respect to the full wave duration. If one o...
def detect_interval( self, min_head_length=None, max_head_length=None, min_tail_length=None, max_tail_length=None ): """ Detect the interval of the audio file containing the fragments in the text file. Return the audio inte...
Detect the audio head, returning its duration, in seconds. :param min_head_length: estimated minimum head length :type min_head_length: :class:`~aeneas.exacttiming.TimeValue` :param max_head_length: estimated maximum head length :type max_head_length: :class:`~aeneas.exacttiming.TimeV...
def detect_head(self, min_head_length=None, max_head_length=None): """ Detect the audio head, returning its duration, in seconds. :param min_head_length: estimated minimum head length :type min_head_length: :class:`~aeneas.exacttiming.TimeValue` :param max_head_length: estimate...
Detect the audio tail, returning its duration, in seconds. :param min_tail_length: estimated minimum tail length :type min_tail_length: :class:`~aeneas.exacttiming.TimeValue` :param max_tail_length: estimated maximum tail length :type max_tail_length: :class:`~aeneas.exacttiming.TimeV...
def detect_tail(self, min_tail_length=None, max_tail_length=None): """ Detect the audio tail, returning its duration, in seconds. :param min_tail_length: estimated minimum tail length :type min_tail_length: :class:`~aeneas.exacttiming.TimeValue` :param max_tail_length: estimate...
Detect the head or tail within ``min_length`` and ``max_length`` duration. If detecting the tail, the real wave MFCC and the query are reversed so that the tail detection problem reduces to a head detection problem. Return the duration of the head or tail, in seconds. :param min_lengt...
def _detect(self, min_length, max_length, tail=False): """ Detect the head or tail within ``min_length`` and ``max_length`` duration. If detecting the tail, the real wave MFCC and the query are reversed so that the tail detection problem reduces to a head detection problem. Ret...
Synthesize multiple text fragments, using the cew extension. Return a tuple (anchors, total_time, num_chars). :rtype: (bool, (list, :class:`~aeneas.exacttiming.TimeValue`, int))
def _synthesize_multiple_c_extension(self, text_file, output_file_path, quit_after=None, backwards=False): """ Synthesize multiple text fragments, using the cew extension. Return a tuple (anchors, total_time, num_chars). :rtype: (bool, (list, :class:`~aeneas.exacttiming.TimeValue`, int...
Perform command and return the appropriate exit code. :rtype: int
def perform_command(self): """ Perform command and return the appropriate exit code. :rtype: int """ if len(self.actual_arguments) < 2: return self.print_help() source_url = self.actual_arguments[0] output_file_path = self.actual_arguments[1] ...
Select the TTS engine to be used by looking at the rconf object.
def _select_tts_engine(self): """ Select the TTS engine to be used by looking at the rconf object. """ self.log(u"Selecting TTS engine...") requested_tts_engine = self.rconf[RuntimeConfiguration.TTS] if requested_tts_engine == self.CUSTOM: self.log(u"TTS engin...
Synthesize the text contained in the given fragment list into a ``wav`` file. Return a tuple ``(anchors, total_time, num_chars)``. :param text_file: the text file to be synthesized :type text_file: :class:`~aeneas.textfile.TextFile` :param string audio_file_path: the path to t...
def synthesize( self, text_file, audio_file_path, quit_after=None, backwards=False ): """ Synthesize the text contained in the given fragment list into a ``wav`` file. Return a tuple ``(anchors, total_time, num_chars)``. ...
Check whether ``ffprobe`` can be called. Return ``True`` on failure and ``False`` on success. :rtype: bool
def check_ffprobe(cls): """ Check whether ``ffprobe`` can be called. Return ``True`` on failure and ``False`` on success. :rtype: bool """ try: from aeneas.ffprobewrapper import FFPROBEWrapper file_path = gf.absolute_path(u"tools/res/audio.mp3", ...
Check whether ``sys.stdin`` and ``sys.stdout`` are UTF-8 encoded. Return ``True`` on failure and ``False`` on success. :rtype: bool
def check_shell_encoding(cls): """ Check whether ``sys.stdin`` and ``sys.stdout`` are UTF-8 encoded. Return ``True`` on failure and ``False`` on success. :rtype: bool """ is_in_utf8 = True is_out_utf8 = True if sys.stdin.encoding not in ["UTF-8", "UTF8"]...
Check whether ``ffmpeg`` can be called. Return ``True`` on failure and ``False`` on success. :rtype: bool
def check_ffmpeg(cls): """ Check whether ``ffmpeg`` can be called. Return ``True`` on failure and ``False`` on success. :rtype: bool """ try: from aeneas.ffmpegwrapper import FFMPEGWrapper input_file_path = gf.absolute_path(u"tools/res/audio.mp3"...
Check whether ``espeak`` can be called. Return ``True`` on failure and ``False`` on success. :rtype: bool
def check_espeak(cls): """ Check whether ``espeak`` can be called. Return ``True`` on failure and ``False`` on success. :rtype: bool """ try: from aeneas.textfile import TextFile from aeneas.textfile import TextFragment from aeneas.tt...
Check whether ``aeneas.tools.*`` can be imported. Return ``True`` on failure and ``False`` on success. :rtype: bool
def check_tools(cls): """ Check whether ``aeneas.tools.*`` can be imported. Return ``True`` on failure and ``False`` on success. :rtype: bool """ try: from aeneas.tools.convert_syncmap import ConvertSyncMapCLI # disabling this check, as it requir...
Check whether Python C extension ``cdtw`` can be imported. Return ``True`` on failure and ``False`` on success. :rtype: bool
def check_cdtw(cls): """ Check whether Python C extension ``cdtw`` can be imported. Return ``True`` on failure and ``False`` on success. :rtype: bool """ if gf.can_run_c_extension("cdtw"): gf.print_success(u"aeneas.cdtw AVAILABLE") return Fals...
Check whether Python C extension ``cmfcc`` can be imported. Return ``True`` on failure and ``False`` on success. :rtype: bool
def check_cmfcc(cls): """ Check whether Python C extension ``cmfcc`` can be imported. Return ``True`` on failure and ``False`` on success. :rtype: bool """ if gf.can_run_c_extension("cmfcc"): gf.print_success(u"aeneas.cmfcc AVAILABLE") return F...
Check whether Python C extension ``cew`` can be imported. Return ``True`` on failure and ``False`` on success. :rtype: bool
def check_cew(cls): """ Check whether Python C extension ``cew`` can be imported. Return ``True`` on failure and ``False`` on success. :rtype: bool """ if gf.can_run_c_extension("cew"): gf.print_success(u"aeneas.cew AVAILABLE") return False ...
Perform all checks. Return a tuple of booleans ``(errors, warnings, c_ext_warnings)``. :param bool tools: if ``True``, check aeneas tools :param bool encoding: if ``True``, check shell encoding :param bool c_ext: if ``True``, check Python C extensions :rtype: (bool, bool, bool)
def check_all(cls, tools=True, encoding=True, c_ext=True): """ Perform all checks. Return a tuple of booleans ``(errors, warnings, c_ext_warnings)``. :param bool tools: if ``True``, check aeneas tools :param bool encoding: if ``True``, check shell encoding :param bool c...
Build the storable string corresponding to this configuration object. :rtype: string
def config_string(self): """ Build the storable string corresponding to this configuration object. :rtype: string """ return (gc.CONFIG_STRING_SEPARATOR_SYMBOL).join( [u"%s%s%s" % (fn, gc.CONFIG_STRING_ASSIGNMENT_SYMBOL, self.data[fn]) for fn in sorted(self.d...
Return a list of tuples ``(field, description, type, default)``, one for each field of the configuration. :param bool sort: if ``True``, return the list sorted by field :param bool as_strings: if ``True``, return formatted strings instead :rtype: list
def parameters(cls, sort=True, as_strings=False): """ Return a list of tuples ``(field, description, type, default)``, one for each field of the configuration. :param bool sort: if ``True``, return the list sorted by field :param bool as_strings: if ``True``, return formatted st...
Set the values for :data:`~aeneas.runtimeconfiguration.RuntimeConfiguration.MFCC_WINDOW_LENGTH` and :data:`~aeneas.runtimeconfiguration.RuntimeConfiguration.MFCC_WINDOW_SHIFT` matching the given granularity level. Currently supported levels: * ``1`` (paragraph) ...
def set_granularity(self, level): """ Set the values for :data:`~aeneas.runtimeconfiguration.RuntimeConfiguration.MFCC_WINDOW_LENGTH` and :data:`~aeneas.runtimeconfiguration.RuntimeConfiguration.MFCC_WINDOW_SHIFT` matching the given granularity level. Currently s...
Set the values for :data:`~aeneas.runtimeconfiguration.RuntimeConfiguration.TTS` and :data:`~aeneas.runtimeconfiguration.RuntimeConfiguration.TTS_PATH` matching the given granularity level. Currently supported levels: * ``1`` (paragraph) * ``2`` (sentence) ...
def set_tts(self, level): """ Set the values for :data:`~aeneas.runtimeconfiguration.RuntimeConfiguration.TTS` and :data:`~aeneas.runtimeconfiguration.RuntimeConfiguration.TTS_PATH` matching the given granularity level. Currently supported levels: * ``1`...
Return the next multiple of this time value, greater than or equal to ``other``. If ``other`` is zero, return this time value. :rtype: :class:`~aeneas.exacttiming.TimeValue`
def geq_multiple(self, other): """ Return the next multiple of this time value, greater than or equal to ``other``. If ``other`` is zero, return this time value. :rtype: :class:`~aeneas.exacttiming.TimeValue` """ if other == TimeValue("0.000"): return...
Returns ``True`` if this interval starts at the given time point. :param time_point: the time point to test :type time_point: :class:`~aeneas.exacttiming.TimeValue` :raises TypeError: if ``time_point`` is not an instance of ``TimeValue`` :rtype: bool
def starts_at(self, time_point): """ Returns ``True`` if this interval starts at the given time point. :param time_point: the time point to test :type time_point: :class:`~aeneas.exacttiming.TimeValue` :raises TypeError: if ``time_point`` is not an instance of ``TimeValue`` ...
Returns ``True`` if this interval ends at the given time point. :param time_point: the time point to test :type time_point: :class:`~aeneas.exacttiming.TimeValue` :raises TypeError: if ``time_point`` is not an instance of ``TimeValue`` :rtype: bool
def ends_at(self, time_point): """ Returns ``True`` if this interval ends at the given time point. :param time_point: the time point to test :type time_point: :class:`~aeneas.exacttiming.TimeValue` :raises TypeError: if ``time_point`` is not an instance of ``TimeValue`` ...
Returns the time value at ``percent`` of this interval. :param percent: the percent :type percent: :class:`~aeneas.exacttiming.Decimal` :raises TypeError: if ``time_point`` is not an instance of ``TimeValue`` :rtype: :class:`~aeneas.exacttiming.TimeValue`
def percent_value(self, percent): """ Returns the time value at ``percent`` of this interval. :param percent: the percent :type percent: :class:`~aeneas.exacttiming.Decimal` :raises TypeError: if ``time_point`` is not an instance of ``TimeValue`` :rtype: :class:`~aeneas...
Move this interval by the given shift ``offset``. The begin and end time points of the translated interval are ensured to be non-negative (i.e., they are maxed with ``0.000``), unless ``allow_negative`` is set to ``True``. :param offset: the shift to be applied :type o...
def offset(self, offset, allow_negative=False, min_begin_value=None, max_end_value=None): """ Move this interval by the given shift ``offset``. The begin and end time points of the translated interval are ensured to be non-negative (i.e., they are maxed with ``0.000``), ...
Returns ``True`` if this interval contains the given time point, excluding its extrema (begin and end). :param time_point: the time point to test :type time_point: :class:`~aeneas.exacttiming.TimeValue` :rtype: bool
def inner_contains(self, time_point): """ Returns ``True`` if this interval contains the given time point, excluding its extrema (begin and end). :param time_point: the time point to test :type time_point: :class:`~aeneas.exacttiming.TimeValue` :rtype: bool """ ...
Return the position of the given other time interval, relative to this time interval, as a ``RELATIVE_POSITION_*`` constant. :param other: the other interval :type other: :class:`~aeneas.exacttiming.TimeInterval` :rtype: int
def relative_position_of(self, other): """ Return the position of the given other time interval, relative to this time interval, as a ``RELATIVE_POSITION_*`` constant. :param other: the other interval :type other: :class:`~aeneas.exacttiming.TimeInterval` :rtype...
Return the intersection between this time interval and the given time interval, or ``None`` if the two intervals do not overlap. :rtype: :class:`~aeneas.exacttiming.TimeInterval` or ``NoneType``
def intersection(self, other): """ Return the intersection between this time interval and the given time interval, or ``None`` if the two intervals do not overlap. :rtype: :class:`~aeneas.exacttiming.TimeInterval` or ``NoneType`` """ relative_position = self.rela...
Return ``True`` if this time interval ends when the given other time interval begins, and both have non zero length. :param other: the other interval :type other: :class:`~aeneas.exacttiming.TimeInterval` :raises TypeError: if ``other`` is not an instance of ``TimeInterval`` ...
def is_non_zero_before_non_zero(self, other): """ Return ``True`` if this time interval ends when the given other time interval begins, and both have non zero length. :param other: the other interval :type other: :class:`~aeneas.exacttiming.TimeInterval` :raises...
Return ``True`` if this time interval ends when the given other time interval begins. :param other: the other interval :type other: :class:`~aeneas.exacttiming.TimeInterval` :raises TypeError: if ``other`` is not an instance of ``TimeInterval`` :rtype: bool
def is_adjacent_before(self, other): """ Return ``True`` if this time interval ends when the given other time interval begins. :param other: the other interval :type other: :class:`~aeneas.exacttiming.TimeInterval` :raises TypeError: if ``other`` is not an instance of `...
Perform command and return the appropriate exit code. :rtype: int
def perform_command(self): """ Perform command and return the appropriate exit code. :rtype: int """ if len(self.actual_arguments) < 2: return self.print_help() input_file_path = self.actual_arguments[0] output_file_path = self.actual_arguments[1] ...
Return ``True`` if the given sync map format is allowed, and ``False`` otherwise. :param sm_format: the sync map format to be checked :type sm_format: Unicode string :rtype: bool
def check_format(self, sm_format): """ Return ``True`` if the given sync map format is allowed, and ``False`` otherwise. :param sm_format: the sync map format to be checked :type sm_format: Unicode string :rtype: bool """ if sm_format not in SyncMapForma...
Add a new fragment to ``syncmap``. :param syncmap: the syncmap to append to :type syncmap: :class:`~aeneas.syncmap.SyncMap` :param identifier: the identifier :type identifier: string :param lines: the lines of the text :type lines: list of string :param begin: th...
def _add_fragment(cls, syncmap, identifier, lines, begin, end, language=None): """ Add a new fragment to ``syncmap``. :param syncmap: the syncmap to append to :type syncmap: :class:`~aeneas.syncmap.SyncMap` :param identifier: the identifier :type identifier: string ...
Parse the given ``input_text`` and append the extracted fragments to ``syncmap``. :param input_text: the input text as a Unicode string (read from file) :type input_text: string :param syncmap: the syncmap to append to :type syncmap: :class:`~aeneas.syncmap.SyncMap`
def parse(self, input_text, syncmap): """ Parse the given ``input_text`` and append the extracted fragments to ``syncmap``. :param input_text: the input text as a Unicode string (read from file) :type input_text: string :param syncmap: the syncmap to append to :t...
Format the given ``syncmap`` as a Unicode string. :param syncmap: the syncmap to output :type syncmap: :class:`~aeneas.syncmap.SyncMap` :rtype: string
def format(self, syncmap): """ Format the given ``syncmap`` as a Unicode string. :param syncmap: the syncmap to output :type syncmap: :class:`~aeneas.syncmap.SyncMap` :rtype: string """ self.log_exc(u"%s is abstract and cannot be called directly" % (self.TAG), No...
Perform command and return the appropriate exit code. :rtype: int
def perform_command(self): """ Perform command and return the appropriate exit code. :rtype: int """ if len(self.actual_arguments) < 1: return self.print_help() if self.has_option([u"-e", u"--examples"]): return self.print_examples(False) ...
Print the examples and exit. :param bool full: if ``True``, print all examples; otherwise, print only selected ones
def print_examples(self, full=False): """ Print the examples and exit. :param bool full: if ``True``, print all examples; otherwise, print only selected ones """ msg = [] i = 1 for key in sorted(self.DEMOS.keys()): example = ...
Print the list of values for the given parameter and exit. If ``parameter`` is invalid, print the list of parameter names that have allowed values. :param parameter: the parameter name :type parameter: Unicode string
def print_values(self, parameter): """ Print the list of values for the given parameter and exit. If ``parameter`` is invalid, print the list of parameter names that have allowed values. :param parameter: the parameter name :type parameter: Unicode string """ ...
Copy files needed to compile the ``cew`` Python C extension on Windows. A glorious day, when Microsoft will offer a decent support for Python and shared libraries, all this mess will be unnecessary and it should be removed. May that day come soon. Return ``True`` if successful, ``False`` otherwise...
def prepare_cew_for_windows(): """ Copy files needed to compile the ``cew`` Python C extension on Windows. A glorious day, when Microsoft will offer a decent support for Python and shared libraries, all this mess will be unnecessary and it should be removed. May that day come soon. Return ...
Check whether the given file is UTF-8 encoded. :param string input_file_path: the path of the file to be checked :rtype: :class:`~aeneas.validator.ValidatorResult`
def check_file_encoding(self, input_file_path): """ Check whether the given file is UTF-8 encoded. :param string input_file_path: the path of the file to be checked :rtype: :class:`~aeneas.validator.ValidatorResult` """ self.log([u"Checking encoding of file '%s'", input_...
Check whether the given string is properly UTF-8 encoded (if ``is_bytes`` is ``True``), it is not empty, and it does not contain reserved characters. :param string string: the byte string or Unicode string to be checked :param bool is_bstring: if True, string is a byte string ...
def check_raw_string(self, string, is_bstring=True): """ Check whether the given string is properly UTF-8 encoded (if ``is_bytes`` is ``True``), it is not empty, and it does not contain reserved characters. :param string string: the byte string or Unicode string to be ch...
Check whether the given job or task configuration string is well-formed (if ``is_bstring`` is ``True``) and it has all the required parameters. :param string config_string: the byte string or Unicode string to be checked :param bool is_job: if ``True``, ``config_string`` is a job config...
def check_configuration_string( self, config_string, is_job=True, external_name=False ): """ Check whether the given job or task configuration string is well-formed (if ``is_bstring`` is ``True``) and it has all the required parameters....
Check whether the given TXT config file contents (if ``is_config_string`` is ``False``) or TXT config string (if ``is_config_string`` is ``True``) is well-formed and it has all the required parameters. :param string contents: the TXT config file contents or TXT config string :pa...
def check_config_txt(self, contents, is_config_string=False): """ Check whether the given TXT config file contents (if ``is_config_string`` is ``False``) or TXT config string (if ``is_config_string`` is ``True``) is well-formed and it has all the required parameters. :pa...
Check whether the given XML config file contents is well-formed and it has all the required parameters. :param string contents: the XML config file contents or XML config string :param bool is_config_string: if ``True``, contents is a config string :rtype: :class:`~aeneas.validator.Vali...
def check_config_xml(self, contents): """ Check whether the given XML config file contents is well-formed and it has all the required parameters. :param string contents: the XML config file contents or XML config string :param bool is_config_string: if ``True``, contents is a co...
Check whether the given container is well-formed. :param string container_path: the path of the container to be checked :param container_format: the format of the container :type container_format: :class:`~aeneas.container.ContainerFormat` :param string config_string: the configuration...
def check_container(self, container_path, container_format=None, config_string=None): """ Check whether the given container is well-formed. :param string container_path: the path of the container to be checked :param container_format: the format of the container :type container...
Return ``True`` if safety checks are disabled. :param string caller: the name of the caller function :rtype: bool
def _are_safety_checks_disabled(self, caller=u"unknown_function"): """ Return ``True`` if safety checks are disabled. :param string caller: the name of the caller function :rtype: bool """ if self.rconf.safety_checks: return False self.log_warn([u"Saf...
Log a validation failure. :param string msg: the error message
def _failed(self, msg): """ Log a validation failure. :param string msg: the error message """ self.log(msg) self.result.passed = False self.result.add_error(msg) self.log(u"Failed")
Check whether the given sequence of bytes is properly encoded in UTF-8. :param bytes bstring: the byte string to be checked
def _check_utf8_encoding(self, bstring): """ Check whether the given sequence of bytes is properly encoded in UTF-8. :param bytes bstring: the byte string to be checked """ if not gf.is_bytes(bstring): self._failed(u"The given string is not a sequence of byte...
Check whether the given Unicode string contains reserved characters. :param string ustring: the string to be checked
def _check_reserved_characters(self, ustring): """ Check whether the given Unicode string contains reserved characters. :param string ustring: the string to be checked """ forbidden = [c for c in gc.CONFIG_RESERVED_CHARACTERS if c in ustring] if len(forbidden) > 0: ...
Check whether the given parameter value is allowed. Log messages into ``self.result``. :param dict parameters: the given parameters
def _check_allowed_values(self, parameters): """ Check whether the given parameter value is allowed. Log messages into ``self.result``. :param dict parameters: the given parameters """ for key, allowed_values in self.ALLOWED_VALUES: self.log([u"Checking allow...
Check whether at least one of the keys in implied_keys is in ``parameters``, when a given ``key=value`` is present in ``parameters``, for some value in values. Log messages into ``self.result``. :param dict parameters: the given parameters
def _check_implied_parameters(self, parameters): """ Check whether at least one of the keys in implied_keys is in ``parameters``, when a given ``key=value`` is present in ``parameters``, for some value in values. Log messages into ``self.result``. :param dict par...
Check whether the given parameter dictionary contains all the required paramenters. Log messages into ``self.result``. :param list required_parameters: required parameters :param dict parameters: parameters specified by the user
def _check_required_parameters( self, required_parameters, parameters ): """ Check whether the given parameter dictionary contains all the required paramenters. Log messages into ``self.result``. :param list required_parameters: required p...
Check that the job object generated from the given container is well formed, that it has at least one task, and that the text file of each task has the correct encoding. Log messages into ``self.result``. :param job: the Job object generated from container :type job: :class:`~a...
def _check_analyzed_job(self, job, container): """ Check that the job object generated from the given container is well formed, that it has at least one task, and that the text file of each task has the correct encoding. Log messages into ``self.result``. :param job: the...
Pretty print warnings and errors. :param bool warnings: if ``True``, also print warnings. :rtype: string
def pretty_print(self, warnings=False): """ Pretty print warnings and errors. :param bool warnings: if ``True``, also print warnings. :rtype: string """ msg = [] if (warnings) and (len(self.warnings) > 0): msg.append(u"Warnings:") for warn...
Convert the audio file at ``input_file_path`` into ``output_file_path``, using the parameters set in the constructor or through the ``parameters`` property. You can skip the beginning of the audio file by specifying ``head_length`` seconds to skip (if it is ``None``, sta...
def convert( self, input_file_path, output_file_path, head_length=None, process_length=None ): """ Convert the audio file at ``input_file_path`` into ``output_file_path``, using the parameters set in the constructor ...
Pretty print representation of this fragment, as ``(identifier, begin, end, text)``. :rtype: string .. versionadded:: 1.7.0
def pretty_print(self): """ Pretty print representation of this fragment, as ``(identifier, begin, end, text)``. :rtype: string .. versionadded:: 1.7.0 """ return u"%s\t%.3f\t%.3f\t%s" % ( (self.identifier or u""), (self.begin if self.beg...
The rate, in characters/second, of this fragment. If the fragment is not ``REGULAR`` or its duration is zero, return ``None``. :rtype: ``None`` or :class:`~aeneas.exacttiming.Decimal` .. versionadded:: 1.2.0
def rate(self): """ The rate, in characters/second, of this fragment. If the fragment is not ``REGULAR`` or its duration is zero, return ``None``. :rtype: ``None`` or :class:`~aeneas.exacttiming.Decimal` .. versionadded:: 1.2.0 """ if ( (sel...
The time interval that this fragment lacks to respect the given max rate. A positive value means that the current fragment is faster than the max rate (bad). A negative or zero value means that the current fragment has rate slower or equal to the max rate (good). Always...
def rate_lack(self, max_rate): """ The time interval that this fragment lacks to respect the given max rate. A positive value means that the current fragment is faster than the max rate (bad). A negative or zero value means that the current fragment has rate slow...
The maximum time interval that can be stolen to this fragment while keeping it respecting the given max rate. For ``REGULAR`` fragments this value is the opposite of the ``rate_lack``. For ``NONSPEECH`` fragments this value is equal to the length of the fragment. For ``H...
def rate_slack(self, max_rate): """ The maximum time interval that can be stolen to this fragment while keeping it respecting the given max rate. For ``REGULAR`` fragments this value is the opposite of the ``rate_lack``. For ``NONSPEECH`` fragments this value is equal to...
Perform command and return the appropriate exit code. :rtype: int
def perform_command(self): """ Perform command and return the appropriate exit code. :rtype: int """ if len(self.actual_arguments) < 2: return self.print_help() audio_file_path = self.actual_arguments[0] mode = self.actual_arguments[1] if mode...
Write intervals to file. :param output_file_path: path of the output file to be written; if ``None``, print to stdout :type output_file_path: string (path) :param intervals: a list of tuples, each representing an interval :type intervals: list of tuple...
def write_to_file(self, output_file_path, intervals, template): """ Write intervals to file. :param output_file_path: path of the output file to be written; if ``None``, print to stdout :type output_file_path: string (path) :param intervals: a l...
Synthesize multiple text fragments, using the cfw extension. Return a tuple (anchors, total_time, num_chars). :rtype: (bool, (list, :class:`~aeneas.exacttiming.TimeValue`, int))
def _synthesize_multiple_c_extension(self, text_file, output_file_path, quit_after=None, backwards=False): """ Synthesize multiple text fragments, using the cfw extension. Return a tuple (anchors, total_time, num_chars). :rtype: (bool, (list, :class:`~aeneas.exacttiming.TimeValue`, int...
Perform command and return the appropriate exit code. :rtype: int
def perform_command(self): """ Perform command and return the appropriate exit code. :rtype: int """ if self.has_option([u"--list-parameters"]): return self.print_parameters() if len(self.actual_arguments) < 2: return self.print_help() c...
Print the list of parameters and exit.
def print_parameters(self): """ Print the list of parameters and exit. """ self.print_info(u"Available parameters:") self.print_generic(u"\n" + u"\n".join(self.PARAMETERS) + u"\n") return self.HELP_EXIT_CODE
Run ``aeneas.cew``, reading input text from file and writing audio and interval data to file.
def main(): """ Run ``aeneas.cew``, reading input text from file and writing audio and interval data to file. """ # make sure we have enough parameters if len(sys.argv) < 6: print("You must pass five arguments: QUIT_AFTER BACKWARDS TEXT_FILE_PATH AUDIO_FILE_PATH DATA_FILE_PATH") ret...
Synthesize the text contained in the given fragment list into a ``wav`` file. :param string audio_file_path: the path to the output audio file :param float c_quit_after: stop synthesizing as soon as reaching this many seconds :param bool c_backwards: s...
def synthesize_multiple(self, audio_file_path, c_quit_after, c_backwards, u_text): """ Synthesize the text contained in the given fragment list into a ``wav`` file. :param string audio_file_path: the path to the output audio file :param float c_quit_after: stop synthesizing as s...
Read from SMIL file. Limitations: 1. parses only ``<par>`` elements, in order 2. timings must have ``hh:mm:ss.mmm`` or ``ss.mmm`` format (autodetected) 3. both ``clipBegin`` and ``clipEnd`` attributes of ``<audio>`` must be populated
def parse(self, input_text, syncmap): """ Read from SMIL file. Limitations: 1. parses only ``<par>`` elements, in order 2. timings must have ``hh:mm:ss.mmm`` or ``ss.mmm`` format (autodetected) 3. both ``clipBegin`` and ``clipEnd`` attributes of ``<audio>`` must be popul...
Return ``True`` if and only if the given ``index`` is valid.
def _is_valid_index(self, index): """ Return ``True`` if and only if the given ``index`` is valid. """ if isinstance(index, int): return (index >= 0) and (index < len(self)) if isinstance(index, list): valid = True for i in index: ...
Check that the interval of the given fragment is within the boundaries of the list. Raises an error if not OK.
def _check_boundaries(self, fragment): """ Check that the interval of the given fragment is within the boundaries of the list. Raises an error if not OK. """ if not isinstance(fragment, SyncMapFragment): raise TypeError(u"fragment is not an instance of SyncMap...
Check that the interval of the given fragment does not overlap any existing interval in the list (except at its boundaries). Raises an error if not OK.
def _check_overlap(self, fragment): """ Check that the interval of the given fragment does not overlap any existing interval in the list (except at its boundaries). Raises an error if not OK. """ # # NOTE bisect does not work if there is a configuration like: ...
Ensure the given start/end fragment indices make sense: if one of them is ``None`` (i.e., not specified), then set it to ``0`` or ``len(self)``.
def _check_min_max_indices(self, min_index=None, max_index=None): """ Ensure the given start/end fragment indices make sense: if one of them is ``None`` (i.e., not specified), then set it to ``0`` or ``len(self)``. """ min_index = min_index or 0 max_index = max_in...
Iterates through the regular fragments in the list (which are sorted). :rtype: generator of (int, :class:`~aeneas.syncmap.SyncMapFragment`)
def regular_fragments(self): """ Iterates through the regular fragments in the list (which are sorted). :rtype: generator of (int, :class:`~aeneas.syncmap.SyncMapFragment`) """ for i, fragment in enumerate(self.__fragments): if fragment.fragment_type == SyncM...
Iterates through the nonspeech fragments in the list (which are sorted). :rtype: generator of (int, :class:`~aeneas.syncmap.SyncMapFragment`)
def nonspeech_fragments(self): """ Iterates through the nonspeech fragments in the list (which are sorted). :rtype: generator of (int, :class:`~aeneas.syncmap.SyncMapFragment`) """ for i, fragment in enumerate(self.__fragments): if fragment.fragment_type == S...
Remove the fragments corresponding to the given list of indices. :param indices: the list of indices to be removed :type indices: list of int :raises ValueError: if one of the indices is not valid
def remove(self, indices): """ Remove the fragments corresponding to the given list of indices. :param indices: the list of indices to be removed :type indices: list of int :raises ValueError: if one of the indices is not valid """ if not self._is_valid_index(in...
Sort the fragments in the list. :raises ValueError: if there is a fragment which violates the list constraints
def sort(self): """ Sort the fragments in the list. :raises ValueError: if there is a fragment which violates the list constraints """ if self.is_guaranteed_sorted: self.log(u"Already sorted, returning") return self.log...
Remove ``NONSPEECH`` fragments from the list. If ``zero_length_only`` is ``True``, remove only those fragments with zero length, and make all the others ``REGULAR``. :param bool zero_length_only: remove only zero length NONSPEECH fragments
def remove_nonspeech_fragments(self, zero_length_only=False): """ Remove ``NONSPEECH`` fragments from the list. If ``zero_length_only`` is ``True``, remove only those fragments with zero length, and make all the others ``REGULAR``. :param bool zero_length_only: remove o...
Return ``True`` if the list has at least one interval with zero length withing ``min_index`` and ``max_index``. If the latter are not specified, check all intervals. :param int min_index: examine fragments with index greater than or equal to this index (i.e., included) :param int max_in...
def has_zero_length_fragments(self, min_index=None, max_index=None): """ Return ``True`` if the list has at least one interval with zero length withing ``min_index`` and ``max_index``. If the latter are not specified, check all intervals. :param int min_index: examine fragments ...
Return ``True`` if the list contains only adjacent fragments, that is, if it does not have gaps. :param int min_index: examine fragments with index greater than or equal to this index (i.e., included) :param int max_index: examine fragments with index smaller than this index (i.e., excluded) ...
def has_adjacent_fragments_only(self, min_index=None, max_index=None): """ Return ``True`` if the list contains only adjacent fragments, that is, if it does not have gaps. :param int min_index: examine fragments with index greater than or equal to this index (i.e., included) :pa...
Add the given fragment to the list (and keep the latter sorted). An error is raised if the fragment cannot be added, for example if its interval violates the list constraints. :param fragment: the fragment to be added :type fragment: :class:`~aeneas.syncmap.SyncMapFragment` :p...
def add(self, fragment, sort=True): """ Add the given fragment to the list (and keep the latter sorted). An error is raised if the fragment cannot be added, for example if its interval violates the list constraints. :param fragment: the fragment to be added :type fragm...
Move all the intervals in the list by the given ``offset``. :param offset: the shift to be applied :type offset: :class:`~aeneas.exacttiming.TimeValue` :raises TypeError: if ``offset`` is not an instance of ``TimeValue``
def offset(self, offset): """ Move all the intervals in the list by the given ``offset``. :param offset: the shift to be applied :type offset: :class:`~aeneas.exacttiming.TimeValue` :raises TypeError: if ``offset`` is not an instance of ``TimeValue`` """ self.lo...
Change the transition point between fragment ``fragment_index`` and the next fragment to the time value ``value``. This method fails silently (without changing the fragment list) if at least one of the following conditions holds: * ``fragment_index`` is negative * ``fra...
def move_transition_point(self, fragment_index, value): """ Change the transition point between fragment ``fragment_index`` and the next fragment to the time value ``value``. This method fails silently (without changing the fragment list) if at least one of the following...
Determine a list of pairs (nonspeech interval, fragment index), such that the nonspeech interval contains exactly one fragment ending inside it (within the given tolerance) and adjacent to the next fragment. :param nonspeech_intervals: the list of nonspeech intervals to be examined ...
def fragments_ending_inside_nonspeech_intervals( self, nonspeech_intervals, tolerance ): """ Determine a list of pairs (nonspeech interval, fragment index), such that the nonspeech interval contains exactly one fragment ending inside it (within the given toler...
Inject nonspeech fragments corresponding to the given intervals in this fragment list. It is assumed that ``pairs`` are consistent, e.g. they are produced by ``fragments_ending_inside_nonspeech_intervals``. :param list pairs: list of ``(TimeInterval, int)`` pairs, ...
def inject_long_nonspeech_fragments(self, pairs, replacement_string): """ Inject nonspeech fragments corresponding to the given intervals in this fragment list. It is assumed that ``pairs`` are consistent, e.g. they are produced by ``fragments_ending_inside_nonspeech_intervals``...
Fix fragments with zero length, enlarging them to have length ``duration``, reclaiming the difference from the next fragment(s), or moving the next fragment(s) forward. This function assumes the fragments to be adjacent. :param duration: set the zero length fragments to have th...
def fix_zero_length_fragments(self, duration=TimeValue("0.001"), min_index=None, max_index=None, ensure_adjacent=True): """ Fix fragments with zero length, enlarging them to have length ``duration``, reclaiming the difference from the next fragment(s), or moving the next fragment...
Compute the accumulated cost matrix, and return it. Return ``None`` if the accumulated cost matrix cannot be computed because one of the two waves is empty after masking (if requested). :rtype: :class:`numpy.ndarray` (2D) :raises: RuntimeError: if both the C extension and ...
def compute_accumulated_cost_matrix(self): """ Compute the accumulated cost matrix, and return it. Return ``None`` if the accumulated cost matrix cannot be computed because one of the two waves is empty after masking (if requested). :rtype: :class:`numpy.ndarray` (2D) :...
Compute the min cost path between the two waves, and return it. Return the computed path as a tuple with two elements, each being a :class:`numpy.ndarray` (1D) of ``int`` indices: :: ([r_1, r_2, ..., r_k], [s_1, s_2, ..., s_k]) where ``r_i`` are the indices in the real wave an...
def compute_path(self): """ Compute the min cost path between the two waves, and return it. Return the computed path as a tuple with two elements, each being a :class:`numpy.ndarray` (1D) of ``int`` indices: :: ([r_1, r_2, ..., r_k], [s_1, s_2, ..., s_k]) where ``r_i``...
Compute the min cost path between the two waves, and return a list of boundary points, representing the argmin values with respect to the provided ``synt_anchors`` timings. If ``synt_anchors`` has ``k`` elements, the returned array will have ``k+1`` elements, accounting ...
def compute_boundaries(self, synt_anchors): """ Compute the min cost path between the two waves, and return a list of boundary points, representing the argmin values with respect to the provided ``synt_anchors`` timings. If ``synt_anchors`` has ``k`` elements, th...
Set the DTW object up.
def _setup_dtw(self): """ Set the DTW object up. """ # check if the DTW object has already been set up if self.dtw is not None: return # check we have the AudioFileMFCC objects if (self.real_wave_mfcc is None) or (self.real_wave_mfcc.middle_mfcc is No...
Print an error message
def print_error(msg): """ Print an error message """ if IS_POSIX: print(u"%s[ERRO] %s%s" % (ANSI_ERROR, msg, ANSI_END)) else: print(u"[ERRO] %s" % (msg))
Print a warning message
def print_success(msg): """ Print a warning message """ if IS_POSIX: print(u"%s[INFO] %s%s" % (ANSI_OK, msg, ANSI_END)) else: print(u"[INFO] %s" % (msg))
Print a warning message
def print_warning(msg): """ Print a warning message """ if IS_POSIX: print(u"%s[WARN] %s%s" % (ANSI_WARNING, msg, ANSI_END)) else: print(u"[WARN] %s" % (msg))
Try to import the aeneas package and return ``True`` if that fails.
def check_import(): """ Try to import the aeneas package and return ``True`` if that fails. """ try: import aeneas print_success(u"aeneas OK") return False except ImportError: print_error(u"aeneas ERROR") print_info(u" Unable to load the aenea...
The entry point for this module
def main(): """ The entry point for this module """ # first, check we can import aeneas package, exiting on failure if check_import(): sys.exit(1) # import and run the built-in diagnostics from aeneas.diagnostics import Diagnostics errors, warnings, c_ext_warnings = Diagnostics.check_al...
Return ``True`` if all the leaves in the subtree rooted at this node are at the same level. :rtype: bool
def is_pleasant(self): """ Return ``True`` if all the leaves in the subtree rooted at this node are at the same level. :rtype: bool """ levels = sorted([n.level for n in self.leaves]) return levels[0] == levels[-1]