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

How to set generation_config, try_trigger_generation and other things like base64.b64decode while using version 1.0.2

Open rutvik106 opened this issue 1 year ago • 0 comments

What would be the v1.0.2 equivalent code for the following code?

async def text_to_speech_input_streaming(voice_id, text_iterator, fast_ws):

    uri = f"wss://api.elevenlabs.io/v1/text-to-speech/{voice_id}/stream-input?model_id=eleven_monolingual_v1"

    async with websockets.connect(uri) as elevenlabs_ws:
        await elevenlabs_ws.send(json.dumps({
            "text": " ",
            "voice_settings": {
                "stability": 0.5,
                "similarity_boost": 0.8
            },
            "generation_config": {
                "chunk_length_schedule": [500, 500, 500, 500]
            },
            "xi_api_key": ELEVEN_LABS_API_KEY,
        }))

        async def listen():
            """Listen to the elevenlabs_websocket for audio data and stream it."""
            while True:
                try:
                    message = await elevenlabs_ws.recv()
                    data = json.loads(message)
                    if data.get("audio"):
                        chunk = base64.b64decode(data["audio"])
                        await fast_ws.send_bytes(chunk)

                    elif data.get('isFinal'):
                        break

                except websockets.exceptions.ConnectionClosed:
                    break

        async for text in text_chunker(text_iterator):
            await elevenlabs_ws.send(json.dumps({"text": text, "try_trigger_generation": False}))

        await elevenlabs_ws.send(json.dumps({"text": " ", "flush": True}))

        await listen()

rutvik106 avatar Mar 27 '24 10:03 rutvik106