elevenlabs 1.0.8 elevenlabs: ^1.0.8 copied to clipboard
Lightweight wrapper for accessing ElevenLabs's Text-To-Speech API and converting the results to MP3 files.
ElevenLabsTTS #
Lightweight wrapper for ElevenLabs's Text-To-Speech API.
Usage #
-
Add the package as a dependency to your
pubspec.yaml
file. -
An audio package is required. I recommend AudioPlayers or just_audio.
-
Initialize ElevenLabs:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize ElevenLabs
ElevenLabs(apiKey: dotenv.get("API_KEY"));
runApp(const MyApp());
}
- Convert your text to a File object: VoiceId's can be found here: https://api.elevenlabs.io/v1/voices
File file = await ElevenLabs.instance.create(
// Your Input
text: text,
// The Voice Id for the Voice.
// See: https://api.elevenlabs.io/v1/voices
voiceId: "ErXwobaYiN019PkySvjV",
// Checks if the file exists by name
// If it exists it gets called from cache, instead from the API.
fileName: "Hello World",
// Higher stability ensures consistency but may result in monotony, therefore
// for longer text, it is recommended to decrease stability.
stability: 1.0,
// Boosting voice clarity and target speaker similarity is achieved by high
// enhancement; however, very high values can produce artifacts, so it's
// essential to find the optimal setting.
similarityBoost: 1.0,
);
- List voices:
final voices = await ElevenLabs.instance.fetchVoices();
for (var i in voices) {
print(
'Voice Name: ${i.name}, Voice ID: ${i.voiceId}, Category: ${i.category}');
}
See example for more details.