电影y:在内存中从文本到语音导入音频 [英] Movie py : importing audio from text-to-speech in memory

查看:15
本文介绍了电影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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆