elevenlabs-python icon indicating copy to clipboard operation
elevenlabs-python copied to clipboard

Problem with certificate using streaming

Open eleph1729 opened this issue 3 years ago • 3 comments

I am trying the sample code for the streaming functionality. However, when calling elevenlabs.stream to play a stream produced by elevenlabs.generate I get :

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)

Grateful for any assistance

eleph1729 avatar Sep 17 '23 09:09 eleph1729

@eleph1729 how did you solve this? I am facing the same issue

mdamir avatar Oct 29 '23 19:10 mdamir

Same issue here. Would appreciate if you posted your solution!

vkodithala avatar Dec 09 '23 04:12 vkodithala

The problem I had was with this bit of code inside tts.py where it connects to a web socket.

  with connect(
            f"wss://api.elevenlabs.io/v1/text-to-speech/{voice.voice_id}/stream-input?model_id={model.model_id}",
            additional_headers=remove_none_from_dict({
                "xi-api-key": api_key or os.environ.get("ELEVEN_API_KEY")
            })
        ) as websocket:

I changed that code so as to create and pass an ssl_context as below. I used certifi.where() to find the location of my certificates:

    ssl_context = ssl.create_default_context(cafile="/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/certifi/cacert.pem")

    with connect(
        f"wss://api.elevenlabs.io/v1/text-to-speech/{voice.voice_id}/stream-input?model_id={model.model_id}",
        ssl_context=ssl_context,
        additional_headers=remove_none_from_dict({
            "xi-api-key": api_key or os.environ.get("ELEVEN_API_KEY")
        })
    ) as websocket:

I'm not a professional, so no idea if this is a sensible way to do it. ChatGPT helped me. Let me know if there is a more elegant way to do it.

eleph1729 avatar Mar 11 '24 18:03 eleph1729