### Launch Gradio TTS Demo Interface Source: https://context7.com/mistralai/voxtral-4b-tts-2603/llms.txt Clone the repository, install Gradio, and launch the interactive demo. Ensure the vLLM server is running before starting the demo. ```bash # Clone the vLLM-Omni repository git clone https://github.com/vllm-project/vllm-omni.git cd vllm-omni # Install Gradio uv pip install gradio==5.50 # Launch the demo (ensure vLLM server is running) python examples/online_serving/voxtral_tts/gradio_demo.py \ --host localhost \ --port 8000 ``` -------------------------------- ### Install vLLM Source: https://github.com/mistralai/voxtral-4b-tts-2603/blob/main/README.md Install the vLLM library from PyPI. Ensure you are using a version greater than or equal to 0.18.0 for compatibility. ```bash uv pip install -U vllm ``` -------------------------------- ### Install vLLM and vLLM-Omni Source: https://context7.com/mistralai/voxtral-4b-tts-2603/llms.txt Install the required vLLM and vLLM-Omni packages using pip. Ensure vLLM is at least version 0.18.0. Also, verify the mistral_common installation version. ```bash uv pip install -U vllm ``` ```bash uv pip install vllm-omni --upgrade ``` ```bash python3 -c "import mistral_common; print(mistral_common.__version__)" ``` -------------------------------- ### Docker Installation for vLLM-Omni Source: https://context7.com/mistralai/voxtral-4b-tts-2603/llms.txt Pull and run the official vLLM-Omni Docker image for a pre-configured deployment environment. Ensure to map the port and enable GPU support. ```bash # Pull and run the official vLLM-Omni Docker image docker pull vllm/vllm-omni:v0.18.0 # Run container with GPU support docker run --gpus all -p 8000:8000 vllm/vllm-omni:v0.18.0 \ vllm serve mistralai/Voxtral-4B-TTS-2603 --omni ``` -------------------------------- ### Install vLLM Omni Source: https://github.com/mistralai/voxtral-4b-tts-2603/blob/main/README.md Install the vLLM Omni package, which provides production-grade support for models like Voxtral TTS. A version greater than or equal to 0.18.0 is recommended. ```bash uv pip install vllm-omni --upgrade # make sure to have >= 0.18.0 ``` -------------------------------- ### Run Voxtral TTS Gradio Demo Source: https://github.com/mistralai/voxtral-4b-tts-2603/blob/main/README.md Clone the vllm-omni repository and install dependencies to run the Gradio demo locally. This allows for interactive testing of the Voxtral TTS model through a web interface. ```shell git clone https://github.com/vllm-project/vllm-omni.git && \ cd vllm-omni && \ uv pip install gradio==5.50 && \ python examples/online_serving/voxtral_tts/gradio_demo.py \ --host \ --port 8000 ``` -------------------------------- ### Generate Speech using cURL (WAV) Source: https://context7.com/mistralai/voxtral-4b-tts-2603/llms.txt Generate speech from text and save it to a WAV file using a cURL command. This example specifies the input text, model, response format, and voice. ```bash # Generate speech and save to file curl -X POST "http://localhost:8000/v1/audio/speech" \ -H "Content-Type: application/json" \ -d '{ "input": "Hello, welcome to our customer support line.", "model": "mistralai/Voxtral-4B-TTS-2603", "response_format": "wav", "voice": "neutral_female" }' \ --output output.wav ``` -------------------------------- ### Generate Speech from Text using Python Source: https://context7.com/mistralai/voxtral-4b-tts-2603/llms.txt Convert text to speech using the `/v1/audio/speech` endpoint with a Python client. This example demonstrates a basic request, including setting the input text, model, response format, and voice preset. It then reads and prints the audio details. ```python import io import httpx import soundfile as sf BASE_URL = "http://localhost:8000/v1" # Basic text-to-speech request payload = { "input": "Paris is a beautiful city!", "model": "mistralai/Voxtral-4B-TTS-2603", "response_format": "wav", "voice": "casual_male", } response = httpx.post(f"{BASE_URL}/audio/speech", json=payload, timeout=120.0) response.raise_for_status() # Read the audio response audio_array, sr = sf.read(io.BytesIO(response.content), dtype="float32") print(f"Got audio: {len(audio_array)} samples at {sr} Hz") # Output: Got audio: 48000 samples at 24000 Hz ``` -------------------------------- ### Start vLLM Server for Voxtral TTS Source: https://context7.com/mistralai/voxtral-4b-tts-2603/llms.txt Launch the Voxtral TTS model server using vLLM with omni support. The server requires a single GPU with at least 16GB of memory. The API will be available at http://localhost:8000. ```bash # Start the model server vllm serve mistralai/Voxtral-4B-TTS-2603 --omni # Server will be available at http://localhost:8000 # API endpoint: http://localhost:8000/v1/audio/speech ``` -------------------------------- ### Generate Speech with Different Voices Source: https://context7.com/mistralai/voxtral-4b-tts-2603/llms.txt Use this function to generate speech from text using various predefined voice presets. Ensure the `httpx` and `soundfile` libraries are installed. ```python import httpx import io import soundfile as sf BASE_URL = "http://localhost:8000/v1" # Generate speech with different voices def generate_speech(text: str, voice: str, output_format: str = "wav") -> tuple: payload = { "input": text, "model": "mistralai/Voxtral-4B-TTS-2603", "response_format": output_format, "voice": voice, } response = httpx.post(f"{BASE_URL}/audio/speech", json=payload, timeout=120.0) response.raise_for_status() audio_array, sr = sf.read(io.BytesIO(response.content), dtype="float32") return audio_array, sr # Example: Generate multilingual greetings greetings = [ ("Hello, how can I help you today?", "neutral_female"), ("Bonjour, comment puis-je vous aider?", "fr_female"), ("Hola, ¿cómo puedo ayudarle hoy?", "es_male"), ("Guten Tag, wie kann ich Ihnen helfen?", "de_female"), ("Ciao, come posso aiutarla oggi?", "it_male"), ] for text, voice in greetings: audio, sample_rate = generate_speech(text, voice) print(f"Voice: {voice}, Samples: {len(audio)}, Rate: {sample_rate} Hz") ``` -------------------------------- ### Generate Speech using cURL (MP3) Source: https://context7.com/mistralai/voxtral-4b-tts-2603/llms.txt Generate speech from text and save it to an MP3 file using a cURL command. This example demonstrates specifying a different response format and a French voice preset. ```bash # Generate speech in MP3 format curl -X POST "http://localhost:8000/v1/audio/speech" \ -H "Content-Type: application/json" \ -d '{ "input": "Votre commande a été confirmée.", "model": "mistralai/Voxtral-4B-TTS-2603", "response_format": "mp3", "voice": "fr_female" }' \ --output output_french.mp3 ``` -------------------------------- ### Verify mistral_common Version Source: https://github.com/mistralai/voxtral-4b-tts-2603/blob/main/README.md Check if the mistral_common library is installed with version 1.10.0 or higher, which is a dependency for vLLM 0.18.0. ```python import mistral_common; print(mistral_common.__version__) ``` -------------------------------- ### Generate Audio in Supported Formats Source: https://context7.com/mistralai/voxtral-4b-tts-2603/llms.txt This function generates speech in various audio formats. The API supports WAV, PCM, FLAC, MP3, AAC, and Opus, all at a 24 kHz sample rate. Ensure `httpx`, `io`, and `soundfile` are installed. ```python import httpx import io import soundfile as sf BASE_URL = "http://localhost:8000/v1" # Supported audio formats SUPPORTED_FORMATS = ["wav", "pcm", "flac", "mp3", "aac", "opus"] def generate_audio_in_format(text: str, voice: str, audio_format: str) -> bytes: """Generate speech in the specified audio format.""" payload = { "input": text, "model": "mistralai/Voxtral-4B-TTS-2603", "response_format": audio_format, "voice": voice, } response = httpx.post(f"{BASE_URL}/audio/speech", json=payload, timeout=120.0) response.raise_for_status() return response.content # Generate the same text in different formats text = "This message will be encoded in multiple audio formats." for fmt in SUPPORTED_FORMATS: audio_data = generate_audio_in_format(text, "neutral_male", fmt) print(f"Format: {fmt}, Size: {len(audio_data)} bytes") # Save audio to files with open("output.wav", "wb") as f: f.write(generate_audio_in_format(text, "neutral_male", "wav")) with open("output.mp3", "wb") as f: f.write(generate_audio_in_format(text, "neutral_male", "mp3")) ``` -------------------------------- ### Batch Speech Generation with Async Source: https://context7.com/mistralai/voxtral-4b-tts-2603/llms.txt This asynchronous function processes multiple text-to-speech requests concurrently for efficient high-throughput workflows. It requires `httpx`, `io`, `asyncio`, and `soundfile`. The results include the index, number of samples, and sample rate for each generated audio. ```python import httpx import io import asyncio import soundfile as sf BASE_URL = "http://localhost:8000/v1" async def generate_speech_async(client: httpx.AsyncClient, text: str, voice: str, index: int) -> dict: """Generate speech asynchronously.""" payload = { "input": text, "model": "mistralai/Voxtral-4B-TTS-2603", "response_format": "wav", "voice": voice, } response = await client.post(f"{BASE_URL}/audio/speech", json=payload, timeout=120.0) response.raise_for_status() audio_array, sr = sf.read(io.BytesIO(response.content), dtype="float32") return {"index": index, "samples": len(audio_array), "sample_rate": sr} async def batch_generate(texts: list[tuple[str, str]]) -> list[dict]: """Process multiple text-to-speech requests concurrently.""" async with httpx.AsyncClient() as client: tasks = [ generate_speech_async(client, text, voice, i) for i, (text, voice) in enumerate(texts) ] results = await asyncio.gather(*tasks) return results ``` -------------------------------- ### Production-Ready Voxtral TTS API Client Source: https://context7.com/mistralai/voxtral-4b-tts-2603/llms.txt Implement a production-ready client for the Voxtral TTS API with automatic retries, exponential backoff for timeouts and server errors, and proper error handling. Requires `httpx`, `soundfile`, and `io`. ```python import io import time import httpx import soundfile as sf from typing import Optional class VoxtralTTSClient: """Production-ready client for Voxtral TTS API.""" def __init__(self, base_url: str = "http://localhost:8000/v1", timeout: float = 120.0): self.base_url = base_url self.timeout = timeout self.model = "mistralai/Voxtral-4B-TTS-2603" def generate_speech( self, text: str, voice: str = "neutral_female", response_format: str = "wav", max_retries: int = 3, ) -> Optional[tuple]: """Generate speech with automatic retries and error handling.""" payload = { "input": text, "model": self.model, "response_format": response_format, "voice": voice, } for attempt in range(max_retries): try: response = httpx.post( f"{self.base_url}/audio/speech", json=payload, timeout=self.timeout, ) response.raise_for_status() audio_array, sr = sf.read(io.BytesIO(response.content), dtype="float32") return audio_array, sr except httpx.TimeoutException: print(f"Attempt {attempt + 1}: Request timed out, retrying...") time.sleep(2 ** attempt) # Exponential backoff except httpx.HTTPStatusError as e: print(f"Attempt {attempt + 1}: HTTP error {e.response.status_code}") if e.response.status_code >= 500: time.sleep(2 ** attempt) else: raise # Client errors should not be retried except Exception as e: print(f"Attempt {attempt + 1}: Unexpected error: {e}") raise return None # Usage client = VoxtralTTSClient() result = client.generate_speech( text="This is a production-ready text-to-speech request.", voice="casual_female", response_format="wav", ) if result: audio, sample_rate = result print(f"Success: {len(audio)} samples at {sample_rate} Hz") else: print("Failed after all retries") ``` -------------------------------- ### Serve Voxtral 4B TTS with vLLM Omni Source: https://github.com/mistralai/voxtral-4b-tts-2603/blob/main/README.md Deploy the Voxtral-4B-TTS-2603 model using the vLLM serve command with the --omni flag. This command is suitable for models that require specific configurations or optimizations provided by vLLM Omni. ```bash vllm serve mistralai/Voxtral-4B-TTS-2603 --omni ``` -------------------------------- ### Batch Text-to-Speech Generation Source: https://context7.com/mistralai/voxtral-4b-tts-2603/llms.txt Process a batch of texts for speech generation using the `batch_generate` function. Ensure `asyncio` is imported for running asynchronous operations. ```python import asyncio # Assume batch_generate is defined elsewhere and imported # async def batch_generate(texts: list[tuple[str, str]]) -> list[dict]: ... # Batch of texts to convert batch_texts = [ ("Welcome to our automated phone system.", "neutral_female"), ("Press one for sales, press two for support.", "neutral_female"), ("Your call is important to us.", "neutral_male"), ("Please hold while we connect you.", "neutral_male"), ("Thank you for calling. Goodbye!", "cheerful_female"), ] # Run batch processing results = asyncio.run(batch_generate(batch_texts)) for result in results: print(f"Item {result['index']}: {result['samples']} samples at {result['sample_rate']} Hz") ``` -------------------------------- ### Python Client for Voxtral TTS Source: https://github.com/mistralai/voxtral-4b-tts-2603/blob/main/README.md Use this Python script to send text to the Voxtral TTS API and receive audio data. Ensure the server is running and accessible at the specified BASE_URL. The response is saved as a WAV file. ```python import io import httpx import soundfile as sf BASE_URL = "http://:8000/v1" payload = { "input": "Paris is a beautiful city!", "model": "mistralai/Voxtral-4B-TTS-2603", "response_format": "wav", "voice": "casual_male", } response = httpx.post(f"{BASE_URL}/audio/speech", json=payload, timeout=120.0) response.raise_for_status() audio_array, sr = sf.read(io.BytesIO(response.content), dtype="float32") print(f"Got audio: {len(audio_array)} samples at {sr} Hz") # you can play the audio with a library like `sounddevice.play` for example ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.