def run(self, input_files, output=None):
"""Run the automatic annotation process on an input.
:param input_files: (list of str) Phonemes, and optionally tokens, audio
:param output: (str) the output name
:returns: (sppasTranscription)
"""
audio_filename, phon_tier, tok_tier, tok_faked_tier = self.get_inputs(input_files)
framerate = None
if audio_filename is not None and AUDIOOPY is True:
audio_speech = audioopy.aio.open(audio_filename)
n = audio_speech.get_nchannels()
framerate = audio_speech.get_framerate()
if n != 1:
audio_speech.close()
raise AudioChannelError(n)
audio_speech.close()
else:
self.logfile.print_message("Audio is unavailable. Aligner is set to 'basic' and no extra option available.", indent=1, status=annots.warning)
self._options['aligner'] = 'basic'
workdir = sppasAlign.fix_workingdir(audio_filename)
if self._options['clean'] is False:
self.logfile.print_message(MSG_WORKDIR.format(dirname=workdir), indent=3, status=None)
media = None
if audio_filename is not None:
extm = os.path.splitext(audio_filename)[1].lower()[1:]
media = sppasMedia(audio_filename, mime_type='audio/' + extm)
logging.info('Alignment of {:s}'.format(audio_filename))
try:
tier_phn, tier_tok, tier_pron = self.convert(phon_tier, tok_tier, tok_faked_tier, audio_filename, workdir)
if media is not None:
tier_phn.set_media(media)
tier_tok.set_media(media)
tier_pron.set_media(media)
trs_output = sppasTranscription(self.name)
trs_output.set_meta('annotation_result_of', input_files[0])
trs_output.set_meta('aligner_name', self._segmenter.get_aligner_name())
trs_output.set_meta('language_iso', 'iso639-3')
trs_output.set_meta('language_name_0', 'Undetermined')
if len(self.__lang) == 3:
trs_output.set_meta('language_code_0', self.__lang)
trs_output.set_meta('language_url_0', 'https://iso639-3.sil.org/code/' + self.__lang)
else:
trs_output.set_meta('language_code_0', 'und')
trs_output.set_meta('language_url_0', 'https://iso639-3.sil.org/code/und')
if framerate is not None:
trs_output.set_meta('media_sample_rate', str(framerate))
trs_output.append(tier_phn)
if tier_tok is not None:
tier_tok.set_media(media)
trs_output.append(tier_tok)
if tier_pron is not None:
tier_pron.set_media(media)
trs_output.append(tier_pron)
except Exception as e:
self.logfile.print_message(str(e))
if self._options['clean'] is True:
shutil.rmtree(workdir)
raise
error = None
output_file = list()
if output is not None:
output_file = self.fix_out_file_ext(output)
try:
parser = sppasTrsRW(output_file)
parser.write(trs_output)
except Exception as e:
error = e
if self._options['clean'] is True:
shutil.rmtree(workdir)
if error is not None:
raise error
if output is not None:
return [output_file]
return trs_output