B Vk_@slddlZddlZddlZddlZddlTddlmZddlmZddZddZ d d Z d d Z d dZ dS)N)*)editor)closingc Cs|}tdt||yHt|d}||WdQRX|jrTtd|ntd|Wn4tk r}zt|t dWdd}~XYnXdS)Nz+ ==> Writing {:d} bytes to audio file: {:s}wbz ==> {:s} is closedz ==> {:s} is NOT closed) readprintformatlenopenwriteclosedIOErrorsysexit) output_filestreambytesfileerrorrE/Users/afif/Project/aws-transcribe-captioning-tools/src/audioUtils.py writeAudio/s rc Cstdtd}tjd|dd}t|}|dddd }t|} t|j|||d d dd } |jd d| | d} | dddkrtdt | |ntddS)Nz% ==> createAudioTrackFromTranslation polly translateT) service_name region_nameuse_sslresults transcriptsr transcript)TextSourceLanguageCodeTargetLanguageCodeTranslatedTexti mp322050) OutputFormat SampleRater!VoiceIdResponseMetadataHTTPStatusCodez3 ==> Successfully called Polly for speech synthesisz- ==> Error calling Polly for speech synthesis) rboto3clientjsonloads getVoiceIdunicodetranslate_textsynthesize_speechwriteAudioStream) regionr sourceLangCodetargetLangCode audioFileNamer.rtempZtranscript_txtvoiceIdZtranslated_txtresponserrrcreateAudioTrackFromTranslationLs    r=c Cs2d|kr.t|d}|}t||WdQRXdS)NZ AudioStream)rr)r<r9routputrrrr5msr5cCs|dkrd}n |dkrd}|S)NesZPenelopedeZMarlener)r8r;rrrr1}s r1cCsHtd}tjdddd}|jdd|t|d}t||t|}|jS) Nrrz us-east-1T)rrrr%r&)r'r(r!r))r-r.r4r1r5Z AudioFileClipZduration)ZtextToSynthesizer8r9r.rr<ZaudiorrrgetSecondsFromTranslations   rA) r-osr/ contextlibZmoviepy.editorZmoviepyrrrr=r5r1rArrrr s  !