How do I fix this error in Python: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work

2.4k Views Asked by At

I have been trying to mess around with some of Eleven Labs API and make a simple program that takes in a string and can use the API to retrun a voice provided by Eleven Labs speaking the string. I've seen people using similar code to this but I always get the same error telling me it couldnt find ffmpeg or avconv. Any help would be grealty appreciated. Here is the code below.

from elevenlabslib import *
import pydub
import pydub.playback
import io


def play(bytesData):
    sound = pydub.AudioSegment.from_file_using_temporary_files(io.BytesIO(bytesData))
    pydub.playback.play(sound)
    return


user = ElevenLabsUser("API_KEY")  # fill in your api key as a string
voice = user.get_voices_by_name("Rachel")[0]  # fill in the name of the voice you want to use. ex: "Rachel"
play(voice.generate_audio_bytes("Test"))  # fill in what you want the ai to say as a string

Ive downloaded all the suggested packages and downloaded ffmpeg for windows but nothing has worked yet. I can see that the request is going through to the Eleven Labs website as my requested string pops up in my history on Eleven Labs but because of the error no audio is returned.

1

There are 1 best solutions below

0
Cowsius On

specify the file path to ffmpeg:

pydub.AudioSegment.converter = 'C:/FFmpeg_PATH/bin/ffmpeg.exe'

example in your code:

from elevenlabslib import *
import pydub
import pydub.playback
import io

pydub.AudioSegment.converter = 'C:/FFmpeg_PATH/bin/ffmpeg.exe'

def play(bytesData):
    sound = pydub.AudioSegment.from_file_using_temporary_files(io.BytesIO(bytesData))
    pydub.playback.play(sound)
    return


user = ElevenLabsUser("API_KEY")  # fill in your api key as a string
voice = user.get_voices_by_name("Rachel")[0]  # fill in the name of the voice you want to use. ex: "Rachel"
play(voice.generate_audio_bytes("Test"))  # fill in what you want the ai to say as a string