
Security News
Knip Hits 500 Releases with v5.62.0, Improving TypeScript Config Detection and Plugin Integrations
Knip hits 500 releases with v5.62.0, refining TypeScript config detection and updating plugins as monthly npm downloads approach 12M.
You need your own API key to use demo.
A simple and powerful wrapper for the Cartesia Sonic Text-to-Speech (TTS) API, providing an easy-to-use interface for generating speech from text in multiple languages with advanced features. The package includes:
Note: To use this wrapper, you need a valid API key from Cartesia. A subscription is required to access the Sonic TTS API. Visit Cartesia Sonic for more information.
Install the sonic-wrapper
package via pip:
pip install sonic-wrapper
Note: The package requires Python 3.9 or higher.
If you plan to use the Gradio web interface, install Gradio:
pip install gradio>=5.0.0
To use the Cartesia Sonic TTS API, you need a valid API key. Obtain an API key by subscribing to the service on the Cartesia Sonic website.
Once you have your API key, you can set it up:
CartesiaVoiceManager
.set-api-key
command.The API key is stored in a .env
file for subsequent use.
from sonic_wrapper import CartesiaVoiceManager
# Initialize the manager with your API key
manager = CartesiaVoiceManager(api_key='your_api_key_here')
Alternatively, if you have set the CARTESIA_API_KEY
environment variable or stored the API key in a .env
file, you can initialize without passing the API key:
manager = CartesiaVoiceManager()
Listing Available Voices:
voices = manager.list_available_voices()
for voice in voices:
print(f"ID: {voice['id']}, Name: {voice['name']}, Language: {voice['language']}")
Filtering Voices by Language and Accessibility:
from sonic_wrapper import VoiceAccessibility
voices = manager.list_available_voices(
languages=['en'],
accessibility=VoiceAccessibility.ONLY_PUBLIC
)
Getting Voice Information:
voice_info = manager.get_voice_info('voice_id')
print(voice_info)
Creating a Custom Voice:
voice_id = manager.create_custom_voice(
name='My Custom Voice',
source='path/to/your_voice_sample.wav',
language='en',
description='This is a custom voice created from my own sample.'
)
Setting the Voice:
manager.set_voice('voice_id')
Adjusting Speed and Emotions:
# Set speech speed (-1.0 to 1.0)
manager.speed = 0.5 # Faster speech
# Set emotions
emotions = [
{'name': 'positivity', 'level': 'high'},
{'name': 'surprise', 'level': 'medium'}
]
manager.set_emotions(emotions)
Generating Speech:
output_file = manager.speak(
text='Hello, world!',
output_file='output.wav'
)
print(f"Audio saved to {output_file}")
Improving Text Before Synthesis:
from sonic_wrapper import improve_tts_text
text = 'Your raw text here.'
improved_text = improve_tts_text(text, language='en')
manager.speak(text=improved_text, output_file='improved_output.wav')
The package includes a CLI tool for interacting with the TTS functionality directly from the terminal.
Set API Key
Set your Cartesia API key:
python -m sonic_wrapper.cli set-api-key your_api_key_here
List Voices
List all available voices:
python -m sonic_wrapper.cli list-voices
With filters:
python -m sonic_wrapper.cli list-voices --language en --accessibility api
Generate Speech
Generate speech from text using a specific voice:
python -m sonic_wrapper.cli generate-speech --text "Hello, world!" --voice "Voice Name or ID"
Additional options:
Specify Output File:
--output output.wav
Adjust Speech Speed:
--speed 0.5 # Speed ranges from -1.0 (slowest) to 1.0 (fastest)
Add Emotions:
--emotions "positivity:medium" "surprise:high"
Valid emotions: anger
, positivity
, surprise
, sadness
, curiosity
Valid intensities: lowest
, low
, medium
, high
, highest
Create Custom Voice
Create a custom voice from an audio file:
python -m sonic_wrapper.cli create-voice --name "My Custom Voice" --source path/to/audio.wav
The Gradio interface provides a user-friendly web application for interacting with the TTS functionality.
Install Gradio (if not already installed):
pip install gradio>=5.0.0
Run the Application:
python app.py
Access the Web Interface:
Open the provided local URL in your web browser.
Try the Gradio interface online without installing anything:
python -m sonic_wrapper.cli generate-speech \
--text "I'm so excited to share this news with you!" \
--voice "Enthusiastic Voice" \
--emotions "positivity:high" "surprise:medium" \
--speed 0.5 \
--output excited_message.wav
Step 1: Create a Custom Voice
python -m sonic_wrapper.cli create-voice \
--name "Custom Voice" \
--source path/to/your_voice_sample.wav \
--description "A custom voice created from my own audio sample."
Step 2: Generate Speech with the Custom Voice
python -m sonic_wrapper.cli generate-speech \
--text "This is my custom voice." \
--voice "Custom Voice" \
--output custom_voice_output.wav
This project is licensed under the MIT License.
FAQs
A simple wrapper for Cartesia Sonic TTS
We found that sonic-wrapper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Knip hits 500 releases with v5.62.0, refining TypeScript config detection and updating plugins as monthly npm downloads approach 12M.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.