### Install Dependencies and Launch Pretraining Source: https://context7.com/canopyai/orpheus-tts/llms.txt Installs necessary Python dependencies for pretraining and launches the training script using accelerate. This example shows a single-node launch. ```bash # Install dependencies pip install transformers trl wandb flash_attn datasets torch # Launch (single node example) accelerate launch pretrain/train.py ``` -------------------------------- ### Run WebRTC Streaming Example Source: https://github.com/canopyai/orpheus-tts/blob/main/additional_inference_options/no_gpu/README.md Launch the WebRTC streaming server for Orpheus TTS. This command starts a local server for real-time audio streaming. ```bash python -m orpheus_cpp ``` -------------------------------- ### Install and Run Finetune Training Script Source: https://github.com/canopyai/orpheus-tts/blob/main/README.md Install necessary Python packages and log in to Hugging Face and Weights & Biases. Then, launch the training script using accelerate. ```bash pip install transformers datasets wandb trl flash_attn torch huggingface-cli login wandb login accelerate launch train.py ``` -------------------------------- ### Install orpheus-cpp Source: https://github.com/canopyai/orpheus-tts/blob/main/additional_inference_options/no_gpu/README.md Install the `orpheus-cpp` Python package. ```bash pip install orpheus-cpp ``` -------------------------------- ### Install Dependencies and Launch Fine-Tuning Source: https://context7.com/canopyai/orpheus-tts/llms.txt Installs necessary Python dependencies for fine-tuning and launches the training script using accelerate. Ensure you are logged into HuggingFace and Weights & Biases. ```bash # Install dependencies pip install transformers datasets wandb trl flash_attn torch # Authenticate huggingface-cli login wandb login # Launch distributed training accelerate launch finetune/train.py ``` -------------------------------- ### Install Pretraining Dependencies Source: https://github.com/canopyai/orpheus-tts/blob/main/pretrain/readme.md Installs necessary libraries for pretraining, including transformers, trl, wandb, flash_attn, datasets, and torch. Ensure compatibility of flash_attn with your environment. ```bash pip install transformers trl wandb flash_attn datasets torch ``` -------------------------------- ### Install llama-cpp-python for Apple Silicon Source: https://github.com/canopyai/orpheus-tts/blob/main/additional_inference_options/no_gpu/README.md Install `llama-cpp-python` with Metal support for MacOS with Apple Silicon. This is an alternative to CPU-only installation. ```console pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/metal ``` -------------------------------- ### Install llama-cpp-python for CPU Source: https://github.com/canopyai/orpheus-tts/blob/main/additional_inference_options/no_gpu/README.md Install `llama-cpp-python` with CPU support. This is required for `orpheus-cpp` to function without a GPU. ```console pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu ``` -------------------------------- ### Launch Pretraining Script Source: https://github.com/canopyai/orpheus-tts/blob/main/pretrain/readme.md Starts the pretraining process using the accelerate library for distributed training. Ensure your configuration file is set up correctly. ```bash accelerate launch pretrain.py ``` -------------------------------- ### Install Orpheus-TTS and Dependencies Source: https://github.com/canopyai/orpheus-tts/blob/main/README.md Navigate to the cloned repository and install the Orpheus-TTS package. It's recommended to use a specific version of vllm if encountering issues. ```bash cd Orpheus-TTS && pip install orpheus-speech # uses vllm under the hood for fast inference vllm pushed a slightly buggy version on March 18th so some bugs are being resolved by reverting to `pip install vllm==0.7.3` after `pip install orpheus-speech` ``` -------------------------------- ### Generate Streaming PCM Audio Source: https://context7.com/canopyai/orpheus-tts/llms.txt Use generate_speech() with a text prompt and voice name to get a generator of PCM audio chunks. Ensure repetition_penalty is >= 1.1 for stable output. This example writes the audio to a WAV file. ```python from orpheus_tts import OrpheusModel import wave, time model = OrpheusModel( model_name="canopylabs/orpheus-tts-0.1-finetune-prod", max_model_len=2048, ) prompt = ( "Man, the way social media has, um, completely changed how we interact " "is just wild, right? Like, we're all connected 24/7 but somehow " "people feel more alone than ever." ) start = time.monotonic() audio_chunks = model.generate_speech( prompt=prompt, voice="tara", # voice identity temperature=0.6, top_p=0.8, max_tokens=1200, repetition_penalty=1.3, stop_token_ids=[49158], ) with wave.open("output.wav", "wb") as wf: wf.setnchannels(1) wf.setsampwidth(2) # 16-bit wf.setframerate(24000) total_frames = 0 for chunk in audio_chunks: wf.writeframes(chunk) total_frames += len(chunk) // (wf.getsampwidth() * wf.getnchannels()) duration = total_frames / 24000 print(f"Generated {duration:.2f}s of audio in {time.monotonic() - start:.2f}s") # Example output: Generated 8.34s of audio in 2.11s ``` -------------------------------- ### Streaming TTS Inference Example Source: https://github.com/canopyai/orpheus-tts/blob/main/additional_inference_options/no_gpu/README.md Perform streaming text-to-speech inference and save the output to a WAV file. This example uses `orpheus-cpp` and `numpy`. ```python from scipy.io.wavfile import write from orpheus_cpp import OrpheusCpp import numpy as np orpheus = OrpheusCpp(verbose=False, lang="en") text = "I really hope the project deadline doesn't get moved up again." buffer = [] for i, (sr, chunk) in enumerate(orpheus.stream_tts_sync(text, options={"voice_id": "tara"})): buffer.append(chunk) print(f"Generated chunk {i}") buffer = np.concatenate(buffer, axis=1) write("output.wav", 24_000, np.concatenate(buffer)) ``` -------------------------------- ### Guide Prosody with Emotion Tags Source: https://context7.com/canopyai/orpheus-tts/llms.txt Insert inline emotion tags directly into the prompt text to influence the model's prosody. Supported English tags include , , , and others. This example demonstrates mixing tags within prose and saving to a WAV file. ```python from orpheus_tts import OrpheusModel import wave model = OrpheusModel(model_name="canopylabs/orpheus-tts-0.1-finetune-prod") # Mix emotion tags naturally within prose prompt = ( "I can't believe we actually pulled it off! " "After all those late nights... I'm honestly exhausted. " " But yeah, really proud of the team." ) with wave.open("emotional.wav", "wb") as wf: wf.setnchannels(1) wf.setsampwidth(2) wf.setframerate(24000) for chunk in model.generate_speech(prompt=prompt, voice="leah", repetition_penalty=1.3): wf.writeframes(chunk) ``` -------------------------------- ### Streaming Inference Example with OrpheusModel Source: https://github.com/canopyai/orpheus-tts/blob/main/README.md Example demonstrating streaming speech synthesis using the OrpheusModel. This code generates audio from a text prompt and saves it to 'output.wav', also printing the generation time and audio duration. ```python from orpheus_tts import OrpheusModel import wave import time model = OrpheusModel(model_name ="canopylabs/orpheus-tts-0.1-finetune-prod", max_model_len=2048) prompt = '''Man, the way social media has, um, completely changed how we interact is just wild, right? Like, we're all connected 24/7 but somehow people feel more alone than ever. And don't even get me started on how it's messing with kids' self-esteem and mental health and whatnot.''' start_time = time.monotonic() syn_tokens = model.generate_speech( prompt=prompt, voice="tara", ) with wave.open("output.wav", "wb") as wf: wf.setnchannels(1) wf.setsampwidth(2) wf.setframerate(24000) total_frames = 0 chunk_counter = 0 for audio_chunk in syn_tokens: # output streaming chunk_counter += 1 frame_count = len(audio_chunk) // (wf.getsampwidth() * wf.getnchannels()) total_frames += frame_count wf.writeframes(audio_chunk) duration = total_frames / wf.getframerate() end_time = time.monotonic() print(f"It took {end_time - start_time} seconds to generate {duration:.2f} seconds of audio") ``` -------------------------------- ### CPU Inference with orpheus-cpp Source: https://context7.com/canopyai/orpheus-tts/llms.txt Wraps a llama.cpp backend for CPU inference, exposing the same streaming interface as the main Orpheus library. Requires installing orpheus-cpp and llama-cpp-python with CPU support. The output is saved as a WAV file. ```python # pip install orpheus-cpp # pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu # (macOS Apple Silicon: use /whl/metal instead of /cpu) from scipy.io.wavfile import write from orpheus_cpp import OrpheusCpp import numpy as np orpheus = OrpheusCpp(verbose=False, lang="en") text = "I really hope the project deadline doesn't get moved up again." buffer = [] for i, (sr, chunk) in enumerate(orpheus.stream_tts_sync(text, options={"voice_id": "tara"})): buffer.append(chunk) print(f"Generated chunk {i}") audio = np.concatenate(buffer, axis=1) write("output_cpu.wav", 24_000, np.concatenate(audio)) # Launch browser-based WebRTC streaming demo: # python -m orpheus_cpp ``` -------------------------------- ### Real-Time HTTP Streaming Server with Flask Source: https://context7.com/canopyai/orpheus-tts/llms.txt A Flask server that exposes a /tts GET endpoint to stream WAV audio in real time. The companion client.html connects directly to the endpoint for in-browser playback. Requires running the Flask app and accessing the /tts endpoint with a prompt. ```python # realtime_streaming_example/main.py — run with: python main.py from flask import Flask, Response, request import struct from orpheus_tts import OrpheusModel app = Flask(__name__) engine = OrpheusModel(model_name="canopylabs/orpheus-tts-0.1-finetune-prod") def create_wav_header(sample_rate=24000, bits_per_sample=16, channels=1): byte_rate = sample_rate * channels * bits_per_sample // 8 block_align = channels * bits_per_sample // 8 return struct.pack( '<4sI4s4sIHHIIHH4sI', b'RIFF', 36, b'WAVE', b'fmt ', 16, 1, channels, sample_rate, byte_rate, block_align, bits_per_sample, b'data', 0, ) @app.route('/tts', methods=['GET']) def tts(): prompt = request.args.get('prompt', 'No prompt provided.') def generate_audio_stream(): yield create_wav_header() for chunk in engine.generate_speech( prompt=prompt, voice="tara", repetition_penalty=1.1, stop_token_ids=[128258], max_tokens=2000, temperature=0.4, top_p=0.9, ): yield chunk return Response(generate_audio_stream(), mimetype='audio/wav') if __name__ == '__main__': app.run(host='0.0.0.0', port=8080, threaded=True) # Test with curl: # curl "http://localhost:8080/tts?prompt=Hello+world" --output hello.wav ``` -------------------------------- ### Client-side Audio Streaming and Playback Source: https://github.com/canopyai/orpheus-tts/blob/main/realtime_streaming_example/client.html Handles form submission to get user prompt, constructs an audio URL, and streams audio using the HTML audio element. Catches and logs playback errors. ```javascript const base_url = `https:// `; document.getElementById("promptForm").addEventListener("submit", function(event) { event.preventDefault(); const prompt = document.getElementById("promptInput").value; const encodedPrompt = encodeURIComponent(prompt); const audioUrl = `${base_url}/tts?prompt= ` + encodedPrompt; // Set the audio element's src to your endpoint to stream and play the audio data const audioPlayer = document.getElementById("audioPlayer"); audioPlayer.src = audioUrl; audioPlayer.load(); audioPlayer.play().catch(err => console.error("Playback error:", err)); }); ``` -------------------------------- ### Emotion and Intonation Tags Source: https://context7.com/canopyai/orpheus-tts/llms.txt Guide the model's prosody by inserting inline emotion tags directly into the prompt text. Supported English tags include ``, ``, ``, and others. ```APIDOC ## Emotion and Intonation Tags Inline emotion tags are inserted directly into the prompt text to guide the model's prosody. Supported English tags: ``, ``, ``, ``, ``, ``, ``, ``. ```python from orpheus_tts import OrpheusModel import wave model = OrpheusModel(model_name="canopylabs/orpheus-tts-0.1-finetune-prod") # Mix emotion tags naturally within prose prompt = ( "I can't believe we actually pulled it off! " "After all those late nights... I'm honestly exhausted. " " But yeah, really proud of the team." ) with wave.open("emotional.wav", "wb") as wf: wf.setnchannels(1) wf.setsampwidth(2) wf.setframerate(24000) for chunk in model.generate_speech(prompt=prompt, voice="leah", repetition_penalty=1.3): wf.writeframes(chunk) ``` ``` -------------------------------- ### Pretraining Configuration Placeholder Source: https://context7.com/canopyai/orpheus-tts/llms.txt This is a placeholder comment indicating that the pretraining configuration file (pretrain/config.yaml) needs to be edited with dataset paths and hyperparameters before launching training. ```bash # Edit pretrain/config.yaml with dataset paths and hyperparameters ``` -------------------------------- ### Initialize OrpheusModel Source: https://context7.com/canopyai/orpheus-tts/llms.txt Instantiate OrpheusModel by passing the HuggingFace model repo ID and any vLLM engine kwargs. Requires CUDA GPU for the production English model. ```python from orpheus_tts import OrpheusModel import torch # Load the production fine-tuned English model (requires CUDA GPU) model = OrpheusModel( model_name="canopylabs/orpheus-tts-0.1-finetune-prod", dtype=torch.bfloat16, max_model_len=2048, # vLLM engine kwarg ) # Available English voices: tara, leah, jess, leo, dan, mia, zac, zoe print(model.available_voices) # ['zoe', 'zac', 'jess', 'leo', 'mia', 'julia', 'leah'] ``` -------------------------------- ### Baseten Cloud Inference with Async Requests Source: https://context7.com/canopyai/orpheus-tts/llms.txt Demonstrates parallel asynchronous streaming requests to a Baseten-hosted Orpheus model. Requires setting the BASETEN_API_KEY environment variable and replacing 'your-model-id' with your deployment ID. The output is saved as a raw WAV file. ```python # prerequisites: set BASETEN_API_KEY env var, replace MODEL with your deployment ID # pip install aiohttp import asyncio, aiohttp, os, uuid MODEL = "your-model-id" HOST = f"https://model-{MODEL}.api.baseten.co/environments/production/predict" API_KEY = os.environ["BASETEN_API_KEY"] async def synthesize(session, prompt, voice="tara"): payload = { "prompt": prompt, "voice": voice, "max_tokens": 4096, "stop_token_ids": [128258, 128009], "request_id": str(uuid.uuid4()), } async with session.post( HOST, json=payload, headers={"Authorization": f"Api-Key {API_KEY}"}, ) as resp: resp.raise_for_status() buf = bytearray() async for chunk in resp.content.iter_chunked(4096): buf.extend(chunk) return bytes(buf) # raw WAV bytes async def main(): async with aiohttp.ClientSession() as session: wav_bytes = await synthesize(session, "Hello from Baseten!") with open("baseten_output.wav", "wb") as f: f.write(wav_bytes) print(f"Saved {len(wav_bytes)} bytes") asyncio.run(main()) ``` -------------------------------- ### Load and Use Watermarker Source: https://context7.com/canopyai/orpheus-tts/llms.txt Loads the watermarker model, embeds a watermark into an audio file, and verifies its authenticity. Requires CUDA for the watermarker model. ```python wm_model = load_watermarker(device="cuda") audio_array, sample_rate = load_audio("output.wav") watermarked_audio, out_sr = watermark(wm_model, audio_array, sample_rate, ORPHEUS_WATERMARK) torchaudio.save("output_watermarked.wav", watermarked_audio, out_sr) audio_to_check, sr = load_audio("output_watermarked.wav") is_authentic = verify(wm_model, audio_to_check, sr, ORPHEUS_WATERMARK) print("Watermark verified:", is_authentic) ``` -------------------------------- ### Fine-Tuning Configuration Source: https://context7.com/canopyai/orpheus-tts/llms.txt Configuration file for fine-tuning Orpheus TTS on custom voices using HuggingFace's Trainer. Specify your HuggingFace dataset path and training hyperparameters. ```yaml # finetune/config.yaml TTS_dataset: "your-hf-username/your-tts-dataset" # HuggingFace dataset path model_name: "canopylabs/orpheus-tts-0.1-pretrained" epochs: 1 batch_size: 1 number_processes: 1 learning_rate: 5.0e-5 save_steps: 5000 pad_token: 128263 save_folder: "checkpoints" project_name: "my-orpheus-finetune" run_name: "custom-voice-v1" ``` -------------------------------- ### OrpheusModel Initialization Source: https://context7.com/canopyai/orpheus-tts/llms.txt Initialize the OrpheusModel by providing the HuggingFace model repository ID and optional vLLM engine arguments. This loads the necessary components for speech synthesis. ```APIDOC ## OrpheusModel — Initialize the TTS Engine `OrpheusModel` wraps vLLM's `AsyncLLMEngine` and loads the SNAC tokenizer. Pass the HuggingFace model repo ID (or the `"medium-3b"` shorthand) together with any vLLM engine kwargs such as `max_model_len`. ```python from orpheus_tts import OrpheusModel import torch # Load the production fine-tuned English model (requires CUDA GPU) model = OrpheusModel( model_name="canopylabs/orpheus-tts-0.1-finetune-prod", dtype=torch.bfloat16, max_model_len=2048, # vLLM engine kwarg ) # Available English voices: tara, leah, jess, leo, dan, mia, zac, zoe print(model.available_voices) # ['zoe', 'zac', 'jess', 'leo', 'mia', 'julia', 'leah'] ``` ``` -------------------------------- ### generate_tokens_sync() - Raw Token Stream Source: https://context7.com/canopyai/orpheus-tts/llms.txt Generate a raw stream of LLM token strings before audio decoding using `generate_tokens_sync`. This is useful for piping token output into a custom decoder or inspecting intermediate representations. ```APIDOC ## generate_tokens_sync() — Raw Token Stream `generate_tokens_sync()` yields the raw LLM token strings before audio decoding. Use this when you want to pipe token output into a custom decoder or inspect the intermediate representation. ```python from orpheus_tts import OrpheusModel model = OrpheusModel(model_name="canopylabs/orpheus-tts-0.1-finetune-prod") token_gen = model.generate_tokens_sync( prompt="Hello, this is a test of the token stream.", voice="zac", request_id="req-custom-001", temperature=0.6, top_p=0.8, max_tokens=800, repetition_penalty=1.3, stop_token_ids=[49158], ) for raw_token in token_gen: # Each token is a string like "" print(raw_token, end="", flush=True) ``` ``` -------------------------------- ### Use Local Orpheus-TTS Package Source: https://github.com/canopyai/orpheus-tts/blob/main/README.md If encountering KV cache errors or issues with `max_model_len`, use the local package by inserting its path into sys.path. This ensures you are using the repository's code, which may contain fixes not yet on PyPI. ```python import sys sys.path.insert(0, 'orpheus_tts_pypi') from orpheus_tts import OrpheusModel ``` -------------------------------- ### Generate Raw Token Stream Source: https://context7.com/canopyai/orpheus-tts/llms.txt Use generate_tokens_sync() to obtain raw LLM token strings before audio decoding. This is useful for piping output to custom decoders or inspecting intermediate representations. The output is printed directly to the console. ```python from orpheus_tts import OrpheusModel model = OrpheusModel(model_name="canopylabs/orpheus-tts-0.1-finetune-prod") token_gen = model.generate_tokens_sync( prompt="Hello, this is a test of the token stream.", voice="zac", request_id="req-custom-001", temperature=0.6, top_p=0.8, max_tokens=800, repetition_penalty=1.3, stop_token_ids=[49158], ) for raw_token in token_gen: # Each token is a string like "" print(raw_token, end="", flush=True) ``` -------------------------------- ### Clone Orpheus-TTS Repository Source: https://github.com/canopyai/orpheus-tts/blob/main/README.md Clone the Orpheus-TTS repository from GitHub. ```bash git clone https://github.com/canopyai/Orpheus-TTS.git ``` -------------------------------- ### generate_speech() - Streaming PCM Audio Generation Source: https://context7.com/canopyai/orpheus-tts/llms.txt Generate speech from text using the `generate_speech` method. This method returns a generator yielding raw PCM audio chunks. It supports specifying a voice, temperature, top_p, max tokens, repetition penalty, and stop token IDs. ```APIDOC ## generate_speech() — Streaming PCM Audio Generation `generate_speech()` is the primary public API. It accepts a text `prompt`, a `voice` name, and standard LLM sampling parameters. It returns a synchronous generator that yields `bytes` chunks of 16-bit PCM audio at 24 kHz. `repetition_penalty >= 1.1` is required for stable output. ```python from orpheus_tts import OrpheusModel import wave, time model = OrpheusModel( model_name="canopylabs/orpheus-tts-0.1-finetune-prod", max_model_len=2048, ) prompt = ( "Man, the way social media has, um, completely changed how we interact " "is just wild, right? Like, we're all connected 24/7 but somehow " "people feel more alone than ever." ) start = time.monotonic() audio_chunks = model.generate_speech( prompt=prompt, voice="tara", # voice identity temperature=0.6, top_p=0.8, max_tokens=1200, repetition_penalty=1.3, stop_token_ids=[49158], ) with wave.open("output.wav", "wb") as wf: wf.setnchannels(1) wf.setsampwidth(2) # 16-bit wf.setframerate(24000) total_frames = 0 for chunk in audio_chunks: wf.writeframes(chunk) total_frames += len(chunk) // (wf.getsampwidth() * wf.getnchannels()) duration = total_frames / 24000 print(f"Generated {duration:.2f}s of audio in {time.monotonic() - start:.2f}s") # Example output: Generated 8.34s of audio in 2.11s ``` ``` -------------------------------- ### Synchronous Token Decoding with tokens_decoder_sync Source: https://context7.com/canopyai/orpheus-tts/llms.txt Converts a synchronous generator of raw LLM token strings into a generator of PCM audio byte chunks using the SNAC 24 kHz codec. Use this to build custom pipelines that produce tokens from sources other than OrpheusModel. ```python from orpheus_tts import tokens_decoder_sync import wave def my_token_source(): """Yield raw custom_token strings from any source.""" tokens = ["", "", ...] # your tokens yield from tokens with wave.open("decoded.wav", "wb") as wf: wf.setnchannels(1) wf.setsampwidth(2) wf.setframerate(24000) for audio_chunk in tokens_decoder_sync(my_token_source()): wf.writeframes(audio_chunk) ``` -------------------------------- ### CLI Watermark Verification Source: https://context7.com/canopyai/orpheus-tts/llms.txt Command-line interface command to verify the watermark of an audio file. ```bash # python watermark.py --audio_path output_watermarked.wav ``` -------------------------------- ### Audio Watermarking with SilentCipher Source: https://context7.com/canopyai/orpheus-tts/llms.txt Uses the SilentCipher module to embed and verify an invisible Orpheus-specific watermark in generated audio. Requires loading the watermarker, audio, and using the watermark and verify functions. ```python from watermark import load_watermarker, watermark, verify, load_audio, ORPHEUS_WATERMARK import torchaudio ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.