Basic Usage

Getting Started with Amphion

This guide will walk you through the basic usage of Amphion's core features.

Text-to-Speech

Here's a simple example of text-to-speech synthesis:

from amphion import TextToSpeech # Initialize the model tts = TextToSpeech() # Basic synthesis audio = tts.synthesize("Hello, world!") audio.save("output.wav") # Synthesis with different speaker audio = tts.synthesize("Hello, world!", speaker="speaker_1") audio.save("output_speaker1.wav") # Synthesis with emotion audio = tts.synthesize("Hello, world!", emotion="happy") audio.save("output_happy.wav")

Voice Conversion

Convert voice from one speaker to another:

from amphion import VoiceConverter # Initialize the converter converter = VoiceConverter() # Convert voice converted_audio = converter.convert( source="input.wav", target_speaker="target_speaker" ) converted_audio.save("converted.wav")

Text-to-Audio

Generate audio from text descriptions:

from amphion import TextToAudio # Initialize the generator generator = TextToAudio() # Generate audio from description audio = generator.generate( "A calm forest ambience with birds chirping and leaves rustling" ) audio.save("forest.wav")

Configuration

You can customize the behavior of Amphion components through configuration:

from amphion import TextToSpeech from amphion.config import Config config = Config( sample_rate=44100, device="cuda", model_path="path/to/custom/model" ) tts = TextToSpeech(config)

Error Handling

Amphion provides clear error messages and exceptions:

try: audio = tts.synthesize("Hello, world!") except ModelNotFoundError: print("Model not found. Please check your installation.") except DeviceNotAvailableError: print("CUDA device not available. Falling back to CPU.")

Next Steps