1 Star 0 Fork 0

hehuolong/AI-Auto-Video-Generator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
voiceover_generator.py 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
BB31420 提交于 2023-05-05 04:31 +08:00 . Add files via upload
import requests
import os
import time
def generate_voiceover(story, save_file=False):
headers = {
"xi-api-key": os.getenv("ELEVENLABS_API_KEY"),
"Content-Type": "application/json",
"accept": "audio/mpeg"
}
data = {
"text": story + "..Comment with your favorite fact...",
"voice_settings": {"stability": 0.3, "similarity_boost": 0.3}
}
response = requests.post("https://api.elevenlabs.io/v1/text-to-speech/AZnzlk1XvdvUeBnXmlld", headers=headers, json=data)
if response.status_code == 200:
if save_file:
with open("file.mp3", "wb") as f:
f.write(response.content)
return response.content
else:
print(f"Error while generating voiceover with status code {response.status_code}")
return None
def save_voiceover(voiceover_content, timestamp):
voiceover_filename = f"voiceover_{timestamp}.mp3"
with open(voiceover_filename, "wb") as f:
f.write(voiceover_content)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hehuolong_admin/AI-Auto-Video-Generator.git
git@gitee.com:hehuolong_admin/AI-Auto-Video-Generator.git
hehuolong_admin
AI-Auto-Video-Generator
AI-Auto-Video-Generator
main

搜索帮助