电影y:在内存中从文本到语音导入音频 [英] Movie py : importing audio from text-to-speech in memory
本文介绍了电影y:在内存中从文本到语音导入音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将Azure的文本到语音转换与movie.py
结合使用,以创建视频的音频流。
result = synthesizer.speak_ssml_async(xml_string).get()
stream = AudioDataStream(result)
此进程的输出为:
<azure.cognitiveservices.speech.AudioDataStream at 0x2320cb87ac0>
但是,movie.py
无法使用以下命令导入:
audioClip = AudioFileClip(stream)
这给了我错误:
AudioDataStream"对象没有属性"endswith""
我是否需要将Azure流转换为.wav
?我该怎么做?我需要完成整个过程,而不是在本地写入.wav
文件(例如stream.save_to_wav_file
),而只需使用内存流。
有人能借个灯吗?
推荐答案
我为您编写了一个HTTrigger PYTHON函数,只需尝试以下代码:
import azure.functions as func
import azure.cognitiveservices.speech as speechsdk
import tempfile
import imageio
imageio.plugins.ffmpeg.download()
from moviepy.editor import AudioFileClip
speech_key="<speech service key>"
service_region="<speech service region>"
temp_file_path = tempfile.gettempdir() + "/result.wav"
text = 'hello, this is a test'
def main(req: func.HttpRequest) -> func.HttpResponse:
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
auto_detect_source_language_config = speechsdk.languageconfig.AutoDetectSourceLanguageConfig()
speech_synthesizer = speechsdk.SpeechSynthesizer(
speech_config=speech_config, auto_detect_source_language_config=auto_detect_source_language_config,audio_config=None)
result = speech_synthesizer.speak_text_async(text).get();
if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
stream = speechsdk.AudioDataStream(result)
stream.save_to_wav_file(temp_file_path)
myclip = AudioFileClip(temp_file_path)
return func.HttpResponse(str(myclip.duration))
逻辑很简单,从语音服务获取语音流并保存到临时文件,然后使用AudioDataStream
获取其持续时间。
如果您还有其他问题,请告诉我。
这篇关于电影y:在内存中从文本到语音导入音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文