### Install FFmpeg on Windows Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/postProcessor.md Instructions to install FFmpeg on Windows. Download the binaries from the official FFmpeg website. This is required for the `set_tempo()` method. ```bash # Download from https://ffmpeg.org/download.html ``` -------------------------------- ### VAD Process Example with Silence Trimming Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/voiceActivityDetection.md Demonstrates the `process` method using a simulated audio signal with silence at the start and end. It shows how the method effectively trims these silent portions. ```python import numpy as np from src.postprocessor.vad import VoiceActivityDetection vad = VoiceActivityDetection() # Audio with silence at start and end audio = np.concatenate([ np.random.randn(800) * 5, # 0.5s silence (low energy) np.random.randn(4000) * 100, # 2.5s speech (high energy) np.random.randn(800) * 5, # 0.5s silence ]) output = vad.process(audio, sc_threshold=40) print(f"Input duration: {len(audio) / 16000:.2f}s") print(f"Output duration: {len(output) / 16000:.2f}s") # Output: ~2.5s (silence trimmed from both ends) ``` -------------------------------- ### Environment Setup for Indic-TTS Source: https://github.com/ai4bharat/indic-tts/blob/master/README.md Commands to set up the necessary environment, including system dependencies, PyTorch, and the Trainer and TTS packages. Includes options for direct installation or copying modified files. ```bash # 1. Create environment sudo apt-get install libsndfile1-dev ffmpeg enchant conda create -n tts-env conda activate tts-env # 2. Setup PyTorch pip3 install -U torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113 # 3. Setup Trainer git clone https://github.com/gokulkarthik/Trainer cd Trainer pip3 install -e .[all] cd .. [or] cp Trainer/trainer/logging/wandb_logger.py to the local Trainer installation # fixed wandb logger cp Trainer/trainer/trainer.py to the local Trainer installation # fixed model.module.test_log and added code to log epoch add `gpus = [str(gpu) for gpu in gpus]` in line 53 of trainer/distribute.py # 4. Setup TTS git clone https://github.com/gokulkarthik/TTS cd TTS pip3 install -e .[all] cd .. [or] cp TTS/TTS/bin/synthesize.py to the local TTS installation # added multiple output support for TTS.bin.synthesis # 5. Install other requirements > pip3 install -r requirements.txt ``` -------------------------------- ### Install Dependencies Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/README.md Install all project dependencies, including those for PyTorch with CUDA support, by referencing the requirements file. ```bash pip install -r requirements-*.txt ``` -------------------------------- ### Example: Trimming Silence from Audio Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/postProcessor.md Illustrates removing leading and trailing silence from an audio signal. The example creates a noisy audio array with silence at the start and end, then trims it. ```python # Audio with leading silence (0.5s) and trailing silence (0.3s) noisy_audio = np.concatenate([ np.zeros(22050 // 2), # 0.5s silence speech_audio, # actual speech np.zeros(22050 // 3), # 0.333s silence ]) trimmed = post_processor.trim_silence(noisy_audio) # Output contains mostly the speech portion with silence removed ``` -------------------------------- ### TTSResponse Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/types.md Illustrates how to construct a TTSResponse object with synthesized audio and configuration details. ```python response = TTSResponse( audio=[ AudioFile(audioContent="UklGRi4AAAB..."), AudioFile(audioContent="UklGRi4AAAB...") ], config=AudioConfig( language=Language(sourceLanguage='hi'), samplingRate=22050 ) ) ``` -------------------------------- ### Install FFmpeg on Ubuntu/Debian Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/postProcessor.md Install FFmpeg on Ubuntu or Debian-based systems. This is required for the `set_tempo()` method. ```bash sudo apt-get install ffmpeg ``` -------------------------------- ### Create AudioConfig Instance Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/types.md Example of creating an AudioConfig instance with specified language, format, encoding, and sampling rate. ```python config = AudioConfig( language=Language(sourceLanguage='hi'), audioFormat='wav', encoding='base64', samplingRate=22050 ) ``` -------------------------------- ### Start FastAPI Server Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/endpoints.md Use this command to start the Indic-TTS inference server. Ensure you are in the correct directory. ```bash uvicorn server:api --host 0.0.0.0 --port 5050 --log-level info ``` -------------------------------- ### REST API Integration Example (JavaScript) Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md JavaScript code using Node.js 'axios' to perform batch synthesis via the TTS API. Requires 'axios' to be installed. ```javascript const axios = require('axios'); const fs = require('fs'); const requestBody = { "input": [ { "text": "வணக்கம் உலகம்", "speaker_id": "ta-IN-x-taf-network", "language": "ta-IN" } ], "audio_config": { "sampling_rate": 24000 } }; axios.post('http://localhost:5000/api/v1/tts', requestBody, { responseType: 'stream' }) .then(response => { const writer = fs.createWriteStream('output.wav'); response.data.pipe(writer); writer.on('finish', () => console.log('Audio saved to output.wav')); }) .catch(error => { console.error('Error:', error); }); ``` -------------------------------- ### Quick Python Example for Indic TTS Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md A basic Python example demonstrating how to use the Indic TTS system for text-to-speech conversion. This snippet is useful for a quick start and understanding the core functionality. ```python from indic_tts.model import TextToSpeech # Initialize the TextToSpeech engine tts_engine = TextToSpeech(config_path="/path/to/your/config.yaml") # Example text for synthesis text = "This is a test sentence." language = "en" # Synthesize speech speech_output = tts_engine.infer_from_text(text, lang=language) # Save the audio to a file with open("output.wav", "wb") as f: f.write(speech_output) print("Audio saved to output.wav") ``` -------------------------------- ### Example: Adjusting Audio Tempo Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/postProcessor.md Demonstrates how to use the `set_tempo` method to slow down audio by 15% and speed it up by 20%. ```python import numpy as np # Original audio at 22050 Hz raw_audio = np.random.randn(22050) # 1 second # Slow down by 15% slow_audio = post_processor.set_tempo(raw_audio, atempo='0.85') # Output has ~1.176 seconds of audio (22050 / 0.85 ≈ 26000 samples) # Speed up by 20% fast_audio = post_processor.set_tempo(raw_audio, atempo='1.20') # Output has ~0.833 seconds of audio (22050 / 1.20 ≈ 18375 samples) ``` -------------------------------- ### Install Denoiser Dependencies Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/denoiser.md Provides the pip command to install the required libraries for the denoiser functionality, including torch, librosa, and asteroid. ```bash pip install torch librosa asteroid ``` -------------------------------- ### Install Translators Library Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/googleTranslator.md Install the translators library using pip. This is a prerequisite for using the GoogleTranslator. ```bash pip install translators ``` -------------------------------- ### Install Python Dependencies for Server Source: https://github.com/ai4bharat/indic-tts/blob/master/inference/README.md Installs Python packages required for hosting the REST API server. This should be run after cloning the repository. ```bash pip install -r requirements-server.txt ``` -------------------------------- ### Install FFmpeg on macOS Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/postProcessor.md Install FFmpeg on macOS using Homebrew. This is required for the `set_tempo()` method. ```bash brew install ffmpeg ``` -------------------------------- ### REST API Integration Example (Python) Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Python code snippet for making a batch synthesis request to the TTS API. Ensure 'requests' library is installed. ```python import requests response = requests.post( "http://localhost:5000/api/v1/tts", json={ "input": [ { "text": "வணக்கம் உலகம்", "speaker_id": "ta-IN-x-taf-network", "language": "ta-IN" } ], "audio_config": { "sampling_rate": 24000 } } ) with open("output.wav", "wb") as f: f.write(response.content) ``` -------------------------------- ### Instantiate Language Model Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/types.md Example of creating a Language model instance for Hindi. ```python lang = Language(sourceLanguage='hi') ``` -------------------------------- ### Denoise Audio Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/denoiser.md Demonstrates how to initialize the Denoiser and apply denoising to a synthetic audio signal. The output is resampled to the target sample rate and converted to float32. ```python import numpy as np from src.postprocessor import Denoiser denoiser = Denoiser(orig_sr=22050, target_sr=16000) # Synthesized speech at 22050 Hz (typically clean but may have artifacts) audio_22k = np.random.randn(44100) # 2 seconds at 22050 Hz # Denoise denoiser = denoiser.denoise(audio_22k) print(f"Input shape: {audio_22k.shape}, dtype: {audio_22k.dtype}") print(f"Output shape: {denoised.shape}, dtype: {denoised.dtype}") # Output shape: (32000,), dtype: float32 (because resampled to 16000 Hz) ``` -------------------------------- ### Install Triton Client Dependencies Source: https://github.com/ai4bharat/indic-tts/blob/master/inference/triton_server/README.md Installs the necessary Python packages for the Triton client. This includes the Triton client library and gevent for asynchronous operations. ```bash pip install tritonclient gevent ``` -------------------------------- ### VoiceActivityDetection add_samples Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Manages the buffering of audio samples for processing. This method is essential for handling continuous audio streams. ```python from indic_tts.voice_activity_detection import VoiceActivityDetection # Initialize VoiceActivityDetection vad = VoiceActivityDetection() # Assume 'new_samples' is a numpy array of new audio samples # Example: new_samples = np.random.rand(512) # Replace with actual audio samples # Add new samples to the internal buffer # vad.add_samples(new_samples) # print("Samples added to buffer.") # Note: This is a conceptual example. Actual usage requires audio sample data. ``` -------------------------------- ### Install Linux Dependencies for Inference Source: https://github.com/ai4bharat/indic-tts/blob/master/inference/README.md Installs necessary system dependencies on Linux for running the TTS inference. Ensure you are in the 'inference' directory before running. ```bash cd inference sudo apt-get install libsndfile1-dev ffmpeg enchant ``` -------------------------------- ### Install Indic-TTS Dependencies Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/README.md Install the necessary Python dependencies for the Indic-TTS server and machine learning components. ```bash pip install -r requirements-server.txt pip install -r requirements-ml.txt ``` -------------------------------- ### TTSConfig Example Usage Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/types.md Instantiates a TTSConfig object for a Hindi male speaker. ```python config = TTSConfig( language=Language(sourceLanguage='hi'), gender='male' ) ``` -------------------------------- ### Instantiate Sentence Model Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/types.md Example of creating a Sentence model instance with Hindi text. ```python sentence = Sentence(source="नमस्ते दुनिया") ``` -------------------------------- ### Complete Indic TTS Workflow Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/types.md Demonstrates how to build a TTS request, serialize it to JSON, and process it using the TextToSpeechEngine. Shows handling of both successful and error responses. ```python import json from src.models.request import TTSRequest, TTSConfig, Sentence from src.models.common import Language from src.inference import TextToSpeechEngine # Build request request = TTSRequest( input=[Sentence(source="नमस्ते")], config=TTSConfig( language=Language(sourceLanguage='hi'), gender='male' ) ) # Serialize to JSON for API request_json = request.json() print(request_json) # { # "input": [{"source": "नमस्ते"}], # "config": { # "language": {"sourceLanguage": "hi"}, # "gender": "male" # } # } # Process and get response response = engine.infer_from_request(request) # Response structure if hasattr(response, 'audio'): # Success (TTSResponse) print(f"Generated {len(response.audio)} audio files") print(f"Sample rate: {response.config.samplingRate} Hz") else: # Error (TTSFailureResponse) print(f"Error: {response.status_text}") ``` -------------------------------- ### Run REST API Server Source: https://github.com/ai4bharat/indic-tts/blob/master/inference/README.md Starts the REST API server for TTS inference. Ensure all prerequisites and dependencies are met before execution. ```bash uvicorn server:api ``` -------------------------------- ### Example: Applying Language and Gender-Specific Processing Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/postProcessor.md Shows how to use the `process` method for different language and gender combinations, including slowdown for Telugu female, speedup for Marathi female after trimming, and speedup for Gujarati. ```python # Example 1: Telugu female (slowdown) te_female_wav = post_processor.process(raw_audio, lang='te', gender='female') # Tempo: 0.85x, silence trimmed # Example 2: Marathi female (speedup) mr_female_wav = post_processor.process(raw_audio, lang='mr', gender='female') # Silence trimmed first, then tempo 1.15x # Example 3: Gujarati any gender (speedup) gu_wav = post_processor.process(raw_audio, lang='gu', gender='male') # Tempo: 1.20x # Example 4: Hindi male (no processing) hi_male_wav = post_processor.process(raw_audio, lang='hi', gender='male') # Returned as-is (or converted to np.ndarray if input was different type) ``` -------------------------------- ### VAD Example with Speech and Silence Frames Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/voiceActivityDetection.md Demonstrates how to use the `vad` method with simulated speech and silence frames. It shows how to initialize the VAD and interpret the boolean results. ```python import numpy as np vad = VoiceActivityDetection() # Simulate speech frame (higher energy) speech_frame = np.random.randn(160) * 100 + 50 # Simulate silence frame (lower energy) silence_frame = np.random.randn(160) * 10 + 2 result_speech = vad.vad(speech_frame, sc_threshold=20) print(f"Speech detected: {result_speech}") # Likely True result_silence = vad.vad(silence_frame, sc_threshold=20) print(f"Silence detected: {not result_silence}") # Likely True ``` -------------------------------- ### Run Triton Server Container Source: https://github.com/ai4bharat/indic-tts/blob/master/inference/triton_server/README.md Starts the Triton server container. This command maps ports, mounts a volume for models, and allocates GPU resources. Adjust '--shm-size' and '--gpus' as needed. ```bash docker run --shm-size=256m --gpus=1 --rm -v ${PWD}/checkpoints/:/models/checkpoints -p 8000:8000 -t tts_triton ``` -------------------------------- ### PostProcessor process Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Applies combined language and gender-specific tuning to the audio. This method is used for advanced audio enhancement tailored to specific linguistic and vocal characteristics. ```python from indic_tts.postprocessor import PostProcessor # Initialize PostProcessor with sample rate postprocessor = PostProcessor(sample_rate=16000) # Path to the input audio file input_audio_path = "input.wav" output_audio_path = "output_processed.wav" # Specify language and gender for tuning language = "en-US" gender = "female" # Process audio with language/gender tuning postprocessor.process(input_audio_path, output_audio_path, lang=language, gender=gender) print(f"Tuned audio saved to {output_audio_path}") ``` -------------------------------- ### Run Indic-TTS FastAPI Server Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/README.md Start the FastAPI server to enable text-to-speech synthesis functionality. The server will be accessible at http://localhost:5050. ```bash uvicorn server:api --host 0.0.0.0 --port 5050 ``` -------------------------------- ### TextToSpeechEngine infer_from_text Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Shows a direct text-to-speech conversion using the infer_from_text method. This is a straightforward way to synthesize speech from a single text input. ```python from indic_tts.model import TextToSpeech # Initialize the TextToSpeech engine tts_engine = TextToSpeech(config_path="/path/to/your/config.yaml") # Text and language for synthesis text_to_synthesize = "Hello world." language_code = "en" # Synthesize speech audio_data = tts_engine.infer_from_text(text_to_synthesize, lang=language_code) # Save the synthesized audio with open("single_output.wav", "wb") as audio_file: audio_file.write(audio_data) print("Single audio saved to single_output.wav") ``` -------------------------------- ### Manually Download Model (Python) Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/denoiser.md Download the denoiser model using Python after installing the huggingface_hub library. This method is useful for programmatic downloads. ```python from huggingface_hub import hf_hub_download hf_hub_download(repo_id="JorisCos/DCCRNet_Libri1Mix_enhsingle_16k", filename="pytorch_model.bin") ``` -------------------------------- ### Decode Base64 Audio Content Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/types.md Example of how to decode the base64 audioContent string and parse it as a WAV file using scipy. ```python # In response audio_file = AudioFile(audioContent="UklGRi4AAABX...") # Decode and parse: import base64 import io wav_bytes = base64.b64decode(audio_file.audioContent) wav_io = io.BytesIO(wav_bytes) import scipy.io.wavfile as wavfile sr, data = wavfile.read(wav_io) ``` -------------------------------- ### TextToSpeechEngine infer_from_request Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Demonstrates batch synthesis using request objects with the TextToSpeech engine. This method is suitable for processing multiple synthesis requests efficiently. ```python from indic_tts.model import TextToSpeech from indic_tts.types import TTSRequest, Sentence, Language # Initialize the TextToSpeech engine tts_engine = TextToSpeech(config_path="/path/to/your/config.yaml") # Create a list of TTSRequest objects requests = [ TTSRequest( sentences=[ Sentence(text="First sentence.", lang=Language(lang_code="en")), Sentence(text="Second sentence.", lang=Language(lang_code="en")), ], config=None, # Use default config or specify TTSConfig ) ] # Perform batch synthesis responses = tts_engine.infer_from_request(requests) # Process the responses (e.g., save audio) for i, response in enumerate(responses): with open(f"batch_output_{i}.wav", "wb") as f: f.write(response.audio) print(f"Batch audio {i} saved.") ``` -------------------------------- ### PostProcessor set_tempo Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Adjusts the speech tempo (speed) using FFmpeg. This method allows fine-tuning the playback speed of the synthesized audio. ```python from indic_tts.postprocessor import PostProcessor # Initialize PostProcessor with sample rate postprocessor = PostProcessor(sample_rate=16000) # Path to the input audio file input_audio_path = "input.wav" output_audio_path = "output_tempo.wav" # Set the desired tempo (e.g., 1.2 for faster speech) tempo_factor = 1.2 # Adjust tempo postprocessor.set_tempo(input_audio_path, output_audio_path, tempo_factor) print(f"Tempo adjusted audio saved to {output_audio_path}") ``` -------------------------------- ### TextNormalizer normalize_decimals Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Shows how decimal numbers are normalized into a word format. This is useful for ensuring consistent pronunciation of numerical values. ```python from indic_tts.text_normalizer import TextNormalizer # Initialize the TextNormalizer tn = TextNormalizer(lang="en") # Text with decimal numbers text_with_decimals = "The temperature is 25.5 degrees Celsius." # Normalize decimals normalized_decimals = tn.normalize_decimals(text_with_decimals) print(f"Original: {text_with_decimals}") print(f"Normalized: {normalized_decimals}") ``` -------------------------------- ### Run FastAPI Server with Uvicorn Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/configuration.md Starts the Uvicorn server for the FastAPI application. Specifies the application module, host, port, and logging level. ```python uvicorn.run( "server:api", host="0.0.0.0", port=5050, log_level="info" ) ``` -------------------------------- ### REST API Integration Example (curl) Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Use this curl command to interact with the TTS API for batch synthesis. Refer to endpoints.md for schema details. ```bash curl -X POST "http://localhost:5000/api/v1/tts" \ -H "Content-Type: application/json" \ -d @request.json ``` -------------------------------- ### VoiceActivityDetection process Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Performs complete audio processing for voice activity detection. This method orchestrates the VAD process over an entire audio input. ```python from indic_tts.voice_activity_detection import VoiceActivityDetection # Initialize VoiceActivityDetection vad = VoiceActivityDetection() # Assume 'audio_data' is a numpy array representing the entire audio signal # Example: audio_data = np.random.rand(16000 * 5) # 5 seconds of audio at 16kHz # Process the audio data to detect speech segments # speech_segments = vad.process(audio_data) # print("Speech segments detected:", speech_segments) # Note: This is a conceptual example. Actual usage requires audio data. ``` -------------------------------- ### Run Triton Client Sample Source: https://github.com/ai4bharat/indic-tts/blob/master/inference/triton_server/README.md Executes the sample client script to interact with the Triton server. This will generate an 'audio.wav' file upon successful execution. ```bash python3 triton_server/client.py ``` -------------------------------- ### Basic Audio Denoising with Denoiser Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/denoiser.md Demonstrates how to initialize the Denoiser and apply it to noisy audio. Ensure the Denoiser is initialized with the correct original and target sample rates. ```python import numpy as np from src.postprocessor import Denoiser denoiser = Denoiser(orig_sr=22050, target_sr=16000) # Simulate TTS output with slight noise tts_output = np.random.randn(22050) * 0.1 # 1 second at 22050 Hz noise = np.sin(2 * np.pi * 8000 * np.arange(22050) / 22050) * 0.01 # 8kHz tone noisy_audio = tts_output + noise # Denoise clean_audio = denoiser.denoise(noisy_audio) print(f"Denoised audio shape: {clean_audio.shape}") print(f"Denoised audio dtype: {clean_audio.dtype}") # Output: (16000,), float32 ``` -------------------------------- ### Create Test Audio Directories Source: https://github.com/ai4bharat/indic-tts/blob/master/preprocessing/FormatDataset-IndicTTS.ipynb Creates new directories to store test audio files, organized by speaker. ```python os.makedirs(f'{data_dir}/wavs-20k-test-male/') os.makedirs(f'{data_dir}/wavs-20k-test-female/') ``` -------------------------------- ### Import Web Framework Libraries Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/module-exports.md Import FastAPI for building web applications, CORSMiddleware for handling Cross-Origin Resource Sharing, and uvicorn as an ASGI server. ```python from fastapi import FastAPI # Web framework from fastapi.middleware.cors import CORSMiddleware # CORS import uvicorn # ASGI server ``` -------------------------------- ### Initialize PostProcessor Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/configuration.md Instantiate the PostProcessor with a target sample rate. ```python PostProcessor(target_sr=16000) ``` -------------------------------- ### Initialize TextToSpeechEngine Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/README.md Instantiate the TextToSpeechEngine with required models and optional parameters for transliteration and denoising. ```python TextToSpeechEngine( models: dict, # Required allow_transliteration: bool = True, # Enable Roman→native enable_denoiser: bool = True # Enable audio enhancement ) ``` -------------------------------- ### GET / Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/README.md Checks the status of the Indic-TTS server. ```APIDOC ## GET / ### Description Checks the status of the Indic-TTS server. ### Method GET ### Endpoint / ### Response #### Success Response (200) - **status** (string) - Indicates the server is running. ``` -------------------------------- ### Initialize TextToSpeechEngine with Denoiser Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/denoiser.md Demonstrates how to instantiate the TextToSpeechEngine with and without the denoiser enabled. Enabling the denoiser defaults the output sample rate to 16000 Hz, while disabling it retains the original model output rate (e.g., 22050 Hz). ```python from src.inference import TextToSpeechEngine # With denoising (default) engine_denoised = TextToSpeechEngine( models=models, enable_denoiser=True ) # Output: 16000 Hz # Without denoising engine_raw = TextToSpeechEngine( models=models, enable_denoiser=False ) # Output: 22050 Hz (original model output) ``` -------------------------------- ### Get Server Status Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Checks the current status of the TTS server. ```APIDOC ## GET / ### Description Checks the current status of the TTS server. ### Method GET ### Endpoint / ``` -------------------------------- ### GET /supported_languages Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/README.md Retrieves a list of languages supported by the Indic-TTS system. ```APIDOC ## GET /supported_languages ### Description Retrieves a list of languages supported by the Indic-TTS system. ### Method GET ### Endpoint /supported_languages ### Response #### Success Response (200) - **languages** (list) - A list of supported language codes. ``` -------------------------------- ### Get Supported Languages Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Retrieves a list of languages supported by the TTS service. ```APIDOC ## GET /supported_languages ### Description Retrieves a list of languages supported by the TTS service. ### Method GET ### Endpoint /supported_languages ``` -------------------------------- ### GET /supported_languages Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/endpoints.md Retrieves a list of all languages supported by the Indic-TTS API, along with their human-readable names. ```APIDOC ## GET /supported_languages ### Description Returns all supported languages and their human-readable names. ### Method GET ### Endpoint /supported_languages ### Parameters None ### Request Example ```bash curl http://localhost:5050/supported_languages ``` ### Response #### Success Response (200) - **{lang_code}** (string) - Language code as key, human-readable name (native script) as value #### Response Example ```json { "as": "Assamese - অসমীয়া", "bn": "Bangla - বাংলা", "brx": "Boro - बड़ो", "en": "English (Indian accent)", "en+hi": "English+Hindi (Hinglish code-mixed)", "gu": "Gujarati - ગુજરાતી", "hi": "Hindi - हिंदी", "kn": "Kannada - ಕನ್ನಡ", "ml": "Malayalam - മലയാളം", "mni": "Manipuri - মিতৈলোন", "mr": "Marathi - मराठी", "or": "Oriya - ଓଡ଼ିଆ", "pa": "Panjabi - ਪੰਜਾਬੀ", "raj": "Rajasthani - राजस्थानी", "ta": "Tamil - தமிழ்", "te": "Telugu - తెలుగు" } ``` ``` -------------------------------- ### TTSFailureResponse Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/types.md Shows how to create a TTSFailureResponse object to indicate a failed synthesis, specifying the error reason. ```python response = TTSFailureResponse( status='ERROR', status_text="Unsupported language!" ) ``` -------------------------------- ### Initialize Denoiser Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/configuration.md Instantiate the Denoiser with original and target sample rates. The original sample rate is typically from TTS models, and the target rate is required by DCCRNet. ```python Denoiser(orig_sr: int, target_sr: int) ``` -------------------------------- ### Define Dataset Configuration Source: https://github.com/ai4bharat/indic-tts/blob/master/preprocessing/AnalyzeDataset-IndicTTS.ipynb Sets up the dataset configuration, specifying the dataset name, metadata file, root path, and language. ```python NUM_PROC = 8 DATASET_CONFIG = BaseDatasetConfig( name="ai4b", meta_file_train="metadata.csv", path="/home/gokulkarthikk/datasets/indictts/ta", language='ta' ) ``` -------------------------------- ### TTSRequest Example Usage Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/types.md Creates a TTSRequest object with two Hindi sentences and a configuration for a male speaker. ```python request = TTSRequest( input=[ Sentence(source="नमस्ते दुनिया"), Sentence(source="आपसे मिलकर खुशी हुई") ], config=TTSConfig( language=Language(sourceLanguage='hi'), gender='male' ) ) ``` -------------------------------- ### FastAPI Route Handler for Supported Languages Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/module-exports.md Defines a GET endpoint to retrieve the dictionary of supported languages. ```python @api.get("/supported_languages") def get_supported_languages() -> dict ``` -------------------------------- ### TextNormalizer convert_numbers_to_words Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Converts numerical digits in a text into their word representations. This is crucial for natural-sounding speech synthesis. ```python from indic_tts.text_normalizer import TextNormalizer # Initialize the TextNormalizer tn = TextNormalizer(lang="en") # Text with numbers text_with_numbers = "There are 10 apples and 5 oranges." # Convert numbers to words text_in_words = tn.convert_numbers_to_words(text_with_numbers) print(f"Original: {text_with_numbers}") print(f"In words: {text_in_words}") ``` -------------------------------- ### Create Azure Machine Learning Environment Source: https://github.com/ai4bharat/indic-tts/blob/master/inference/triton_server/azure_ml/README.md Create a new Azure Machine Learning environment using a YAML configuration file. This environment defines the dependencies and settings for your ML tasks. ```bash az ml environment create -f azure_ml/environment.yml -g $RESOURCE_GROUP -w $WORKSPACE_NAME ``` -------------------------------- ### VoiceActivityDetection get_frame Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Extracts a single audio frame from the buffered samples. This is used in conjunction with `add_samples` for frame-by-frame processing. ```python from indic_tts.voice_activity_detection import VoiceActivityDetection # Initialize VoiceActivityDetection vad = VoiceActivityDetection() # Assume samples have been added using add_samples() # Get the next audio frame # audio_frame = vad.get_frame() # if audio_frame is not None: # print("Audio frame extracted.") # else: # print("No complete frame available yet.") # Note: This is a conceptual example. Actual usage requires prior sample addition. ``` -------------------------------- ### Denoiser Initialization Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/denoiser.md Initializes the Denoiser, setting up sample rate conversion and loading the DCCRNet model. It automatically detects and uses CUDA if available, otherwise falls back to CPU. ```APIDOC ## Denoiser Constructor ### Description Initializes the Denoiser with sample rate conversion and loads the pre-trained DCCRNet model. ### Method Signature `__init__(self, orig_sr: int, target_sr: int)` ### Parameters #### Path Parameters - **orig_sr** (int) - Required - Original sample rate of input audio (e.g., 22050 Hz from TTS models). - **target_sr** (int) - Required - Target sample rate for denoising (16000 Hz). DCCRNet is trained on 16kHz audio. ### Initialization Details - Stores sample rates. - Detects and uses CUDA GPU if available, else CPU. - Downloads and loads pre-trained DCCRNet model from Hugging Face. - Moves model to device (GPU or CPU). - Model is ready for inference immediately after construction. ### Model Details - **Name**: DCCRNet_Libri1Mix_enhsingle_16k - **Source**: Hugging Face (JorisCos/DCCRNet_Libri1Mix_enhsingle_16k) - **Training Data**: Libri1Mix (LibriSpeech + noise mixtures) - **Input**: Mono audio at 16000 Hz - **Output**: Denoised mono audio at 16000 Hz - **Auto-Download**: First initialization downloads ~100MB model (cached thereafter) ### Example ```python from src.postprocessor import Denoiser # Initialize for converting from 22050 Hz to 16000 Hz denoiser = Denoiser(orig_sr=22050, target_sr=16000) # Check device print(f"Using device: {denoiser.device}") # cuda or cpu ``` ``` -------------------------------- ### Manually Download Model (Bash) Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/denoiser.md Use this command to manually download the denoiser model if the automatic download fails. This is for Linux/Mac environments. ```bash # Download manually (Linux/Mac) huggingface-cli download JorisCos/DCCRNet_Libri1Mix_enhsingle_16k ``` -------------------------------- ### TextNormalizer convert_char2phone Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Converts characters to their phonetic representations. This is a low-level utility for text processing, often used internally. ```python from indic_tts.text_normalizer import TextNormalizer # Initialize the TextNormalizer tn = TextNormalizer(lang="en") # Character to convert char_to_convert = "a" # Get phonetic representation phone = tn.convert_char2phone(char_to_convert) print(f"Character: {char_to_convert}") print(f"Phonetic: {phone}") ``` -------------------------------- ### TextNormalizer replace_punctutations Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Demonstrates the replacement of punctuation marks with their word equivalents or removal. This helps in cleaner text for TTS. ```python from indic_tts.text_normalizer import TextNormalizer # Initialize the TextNormalizer tn = TextNormalizer(lang="en") # Text with punctuation text_with_punct = "Hello! How are you? I'm fine." # Replace punctuation processed_text = tn.replace_punctutations(text_with_punct) print(f"Original: {text_with_punct}") print(f"Processed: {processed_text}") ``` -------------------------------- ### Prepare Source and Destination Paths for Resampling Source: https://github.com/ai4bharat/indic-tts/blob/master/preprocessing/FormatDataset-IndicTTS.ipynb Generates lists of source and destination file paths for all audio files in the 'wavs' directory. It also creates a list of target sample rates, all set to 22050 Hz. ```python fps_src = [f'{data_dir_new}/wavs/{fn}' for fn in tqdm(os.listdir(f'{data_dir_new}/wavs'))] fps_dst = [f'{data_dir_new}/wavs-20k/{fn}' for fn in tqdm(os.listdir(f'{data_dir_new}/wavs'))] srs = [22050] * len(fps_src) ``` -------------------------------- ### Import Neural Network Libraries Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/module-exports.md Import PyTorch for general deep learning tasks and Asteroid for denoising models. ```python import torch # PyTorch from asteroid.models import BaseModel as AsteroidBaseModel # Denoising models ``` -------------------------------- ### Get Server Status Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/endpoints.md This endpoint returns a plain text message indicating the server is running. No request body is needed. ```text AI4Bharat Text-To-Speech API ``` ```bash curl http://localhost:5050/ ``` -------------------------------- ### VoiceActivityDetection vad Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Performs single-frame speech/silence classification. This is a core component for detecting voice activity within audio streams. ```python from indic_tts.voice_activity_detection import VoiceActivityDetection # Initialize VoiceActivityDetection vad = VoiceActivityDetection() # Assume 'audio_frame' is a numpy array representing audio samples for a frame # Example: audio_frame = np.random.rand(1024) # Replace with actual audio frame data # Classify the frame as speech or silence # is_speech = vad.vad(audio_frame) # print(f"Is speech: {is_speech}") # Note: This is a conceptual example. Actual usage requires audio frame data. ``` -------------------------------- ### Import Paths for Audio Processing Utilities Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/module-exports.md Imports utility classes for audio post-processing, including denoising and voice activity detection. ```python # Audio processing from src.postprocessor import PostProcessor, Denoiser, VoiceActivityDetection ``` -------------------------------- ### TextNormalizer convert_dates_to_words Example Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/INDEX.md Converts date formats into their spoken word equivalents. This ensures dates are read out naturally by the TTS system. ```python from indic_tts.text_normalizer import TextNormalizer # Initialize the TextNormalizer tn = TextNormalizer(lang="en") # Text with dates text_with_dates = "The meeting is on 2023-10-26." # Convert dates to words text_with_date_words = tn.convert_dates_to_words(text_with_dates) print(f"Original: {text_with_dates}") print(f"With date words: {text_with_date_words}") ``` -------------------------------- ### Import Audio Processing Libraries Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/module-exports.md Import libraries for audio manipulation, including core synthesis, WAV file writing, resampling, and general audio I/O. ```python from TTS.utils.synthesizer import Synthesizer # Core synthesis from scipy.io.wavfile import write as scipy_wav_write # WAV writing import librosa # Resampling import soundfile as sf # Audio I/O ``` -------------------------------- ### PostProcessor Constructor Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/postProcessor.md Initializes the PostProcessor with a target sample rate and a voice activity detector for silence trimming. ```APIDOC ## PostProcessor Constructor ### Description Initializes the PostProcessor with a target sample rate and a voice activity detector for silence trimming. ### Method __init__ ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from src.postprocessor import PostProcessor # For 16000 Hz output post_processor = PostProcessor(target_sr=16000) ``` ### Response #### Success Response (None) None #### Response Example None ERROR HANDLING: None ``` -------------------------------- ### Get Supported Languages Source: https://github.com/ai4bharat/indic-tts/blob/master/_autodocs/module-exports.md Retrieves a dictionary of all languages supported by the Indic TTS system, including their language codes and full names. ```APIDOC ## GET /supported_languages ### Description Retrieves a dictionary of all languages supported by the Indic TTS system. ### Method GET ### Endpoint /supported_languages ### Response #### Success Response (200) - **languages** (dict) - A dictionary where keys are language codes and values are the full language names. ```