def create_zip_file(tts_info_list, name, UUID): if len(tts_info_list) == 0: return '' zip_file_name = '/tmp/export.zip' zip_file_key = name + '.zip' unique_zip_key = get_id_package_name(name, UUID) + ".zip" zf = zipfile.ZipFile(zip_file_name, 'w') character_mapping = {} speech_line_definitions = [] character_custom_mapping = 'Character' line_custom_mapping = 'Line' custom_mappings = tts.get_custom_mappings() for key, value in custom_mappings.items(): if value == 'character': character_custom_mapping = key elif value == 'line': line_custom_mapping = key speech_lines_header = [ character_custom_mapping, line_custom_mapping, 'MD5' ] for tts_info in tts_info_list: character_info = character_config.get_character_info( tts_info['character']) tts_info['voice'] = character_info['voice'] tts_info['message'] = tts.add_prosody_tags_to_message( tts_info['line'], character_info) tts_info['speechMarks'] = character_info['speechMarks'] character_mapping[tts_info['character']] = { 'voice': character_info['voice'], 'speechMarks': character_info['speechMarks'] } if character_info.get('ssmlProsodyTags', []): character_mapping[tts_info['character']][ 'ssmlTags'] = character_info['ssmlProsodyTags'] if character_info.get('ssmlLanguage', ''): character_mapping[tts_info['character']][ 'ssmlLanguage'] = character_info['ssmlLanguage'] if character_info.get('timbre', ''): character_mapping[ tts_info['character']]['timbre'] = character_info['timbre'] __add_speech_line_definition(tts_info, speech_line_definitions, speech_lines_header) __update_spoken_line_file(tts_info, zip_file_name) __update_speech_marks_file(tts_info, zip_file_name) __create_character_mappings_file(zip_file_name, character_mapping) __create_speech_definitions_file(zip_file_name, speech_line_definitions, speech_lines_header) __upload_zip_file(zip_file_name, zip_file_key) __upload_zip_file(zip_file_name, unique_zip_key) message = 'The zip file {} is generated successfully.'.format(zip_file_key) print(message)
def post(request, speech): character_info = character_config.get_character_info(speech["character"]) voice = character_info["voice"] speech_marks = character_info["speechMarks"] message = speech["line"] message = tts.add_prosody_tags_to_message(message, character_info) request_info = { "voice": voice, "message": message, "speechMarks": speech_marks } if speech_marks: return { "audioUrl": tts.get_voice(request_info, True), "speechMarksUrl": tts.get_speech_marks(request_info, True) } else: return { "audioUrl": tts.get_voice(request_info, True), "speechMarksUrl": "" }
def get(request, name): return character_config.get_character_info(name)