代码拉取完成,页面将自动刷新
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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。