当我尝试使用elevenlabs API 生成并播放一些语音时,程序开头会出现以下文本:
Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
尽管 ffmpeg 已正确安装并被 Powershell 识别,但还是出现这种情况。相关代码如下。
import openai, requests, ffmpeg, pydub
from elevenlabs import *
set_api_key('i have my key here')
pydub.AudioSegment.converter = 'C:/ffmpeg/bin/ffmpeg.exe'
audio = generate(
text=(response["choices"][0]["message"]["content"]), #<--- This is correct, and grabs the text I need.
voice="Charlie",
model='eleven_multilingual_v1'
)
play(audio)
我希望它只是播放通过我的默认 Windows 播放设备生成的音频,但在播放时遇到崩溃错误;
ValueError: ffplay from ffmpeg not found, necessary to play audio.
https://github.com/elevenlabs/elevenlabs-python/issues/56
如果您使用的是虚拟环境,路径中可能没有 ffmpeg,请尝试添加:
导入操作系统 os.environ['PATH'] += os.pathsep + '/path/to/ffmpeg/bin/'