#When using the websocket to generate audio, I am using the flush() command to force the generation
1 messages · Page 1 of 1 (latest)
The flush command is used to force the generation of audio. It's particularly useful when you want to ensure that the last chunk of audio is generated even when the length of text sent is smaller than the value set in chunk_length_schedule (e.g. 120 or 50).
However, the isFinal field in the response message from the server indicates if the generation is complete. If set to True, audio will be null. If you're not receiving isFinal even though you only received one packet, it might be due to some issues with the streaming or the generation process.
Please ensure that you're using the flush command correctly. When you have finished sending text but want to keep the websocket connection open, set this value to true.
Here's an example of how to use the flush command:
{
"text": "This is a sample text ",
"generation_config": {
"flush": true
}
}
If you're still facing issues, it might be due to network instability or other technical issues. Please check your network connection and try again. If the problem persists, it might be best to reach out to the technical support team for further assistance.
Title: Reducing Latency - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/reducing-latency
Title: How to send an AI message through a phone call using Twilio and ElevenLabs in Node.js - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/integrating-with-twilio
Title: Python Guide - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/python-text-to-speech-guide
Title: Websockets - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/websockets
Title: Reducing Latency - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/reducing-latency
Title: Python Guide - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/python-text-to-speech-guide
Title: Websockets - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/websockets
Title: Websockets - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/websockets
Heading ID: N/A
Heading Value: Websockets
Heading Slug: websockets
Title: Websockets - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/websockets
Title: How to send an AI message through a phone call using Twilio and ElevenLabs in Node.js - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/integrating-with-twilio
show me an example in python where we send a small chunk of text (20 characeters or so) and then call the flush command
Here's an example in Python where we send a small chunk of text (around 20 characters) and then call the flush command:
import asyncio
import websockets
import json
async def text_to_speech(voice_id):
model = 'eleven_monolingual_v1'
uri = f"wss://api.elevenlabs.io/v1/text-to-speech/{voice_id}/stream-input?model_id={model}"
async with websockets.connect(uri) as websocket:
# Initialize the connection
bos_message = {
"text": " ",
"voice_settings": {
"stability": 0.5,
"similarity_boost": 0.8
},
"xi_api_key": "YOUR_API_KEY_HERE"
}
await websocket.send(json.dumps(bos_message))
# Send a small chunk of text (around 20 characters)
input_message = {
"text": "A small chunk of text"
}
await websocket.send(json.dumps(input_message))
# Call the flush command
flush_message = {
"text": " ",
"flush": True
}
await websocket.send(json.dumps(flush_message))
# Send EOS message
eos_message = {
"text": ""
}
await websocket.send(json.dumps(eos_message))
# Handle server responses
while True:
try:
response = await websocket.recv()
data = json.loads(response)
print("Server response:", data)
except websockets.exceptions.ConnectionClosed:
print("Connection closed")
break
asyncio.get_event_loop().run_until_complete(text_to_speech("YOUR_VOICE_ID_HERE"))
In this example, we:
- Initialize the connection by sending the BOS (Beginning of Sequence) message.
- Send a small chunk of text (around 20 characters) with the
input_message. - Call the
flushcommand by sending a message with"flush": True. This will force the generation of audio even though the length of text sent is smaller than the default chunk length schedule. - Send the EOS (End of Sequence) message to close the connection.
- Handle the server responses and print them.
Note that you need to replace "YOUR_API_KEY_HERE" with your actual API key, and "YOUR_VOICE_ID_HERE" with the voice ID you want to use.
Title: Python Guide - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/python-text-to-speech-guide
Title: Text To Speech - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/text-to-speech
Title: Websockets - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/websockets
Title: Websockets - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/websockets
Title: Websockets - ElevenLabs
Path: https://elevenlabs.io/docs/api-reference/websockets
previously you stated to include flush in a "generation_config" key, now you are showing me something different