Aus öffentlichen Paketdaten erstellte Orientierung.
Ein einheitliches Flutter-Paket, das eine einzige Schnittstelle zur Integration von Sprachsynthesefunktionen aus den Cloud-Diensten von Google, Microsoft und Amazon bereitstellt. Es vereinfacht die Implementierung von Sprachausgabe über mehrere Plattformen hinweg, indem es provider-spezifische APIs abstrahiert. Entwickler können zwischen Anbietern mit minimalen Codeänderungen wechseln und so skalierbare und flexible TTS-Lösungen in Apps mit natürlich klingender Sprachsynthese erstellen. Das Paket unterstützt Android, iOS, Web, macOS, Windows und Linux und ist daher ideal für plattformübergreifende sprachgesteuerte Anwendungen.
Anwendungsfälle
plattformübergreifende Sprachassistenten
E-Learning-Anwendungen mit Audio-Narration
Barrierefreie Funktionen in Apps
Mehrsprachige Sprachausgabe
Automatisierte Sprachantworten in Chatbots
Hauptmerkmale
Einheitliche API für Google, Microsoft und AWS TTS
Unterstützt mehrere Sprachen und Stimmen
plattformunabhängige Implementierung
Einfacher Anbieterwechsel
Eingebaute Fehlerbehandlung und Wiederholungen
Unterstützung für Audio-Streaming in Echtzeit
Geeignet für
Entwickler, die Multi-Provider-TTS-Apps erstellen
Apps, die eine konsistente Sprachausgabe über Plattformen hinweg benötigen
Projekte, die eine schnelle Prototypenerstellung von Sprachmerkmalen erfordern
Teams, die mehrere Cloud-TTS-Dienste verwenden
Hinweise
API-Schlüssel für jeden Cloud-Anbieter erforderlich
Die Abrechnung erfolgt basierend auf dem Nutzungsvolumen
Netzwerkverbindung für Cloud-Aufrufe erforderlich
Eingeschränkte Offline-Funktionen
Die Sprachqualität hängt vom ausgewählten Anbieter und der Region ab
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
Cloud Text-To-Speech
Single interface to Google, Microsoft, and Amazon Text-To-Speech.
Flutter implementation of:
Universal implementation for accessing all providers with one interface.
Separate implementation for every provider so we could access every functionality.
Sanitize SSML input per provider so we send only supported SSML elements.
Locale names in English and native language so we could display language selector.
Fake name generation for Google voices that are generated randomly based on voice locale.
Accessible configurable output format (per provider), rate, and pitch.
Feature Requests
We welcome and value your ideas and suggestions to improve this project! To submit and vote for feature requests, please visit our Feature Requests Board.
On the board, you can:
Submit new feature requests: Share your ideas on how we can enhance the project.
Vote on existing requests: Help prioritize the most popular features by voting for the ones you find most valuable.
Thank you for contributing to the development and improvement of Cloud Text-To-Speech!
Getting Started
There are essentially two ways to use Cloud Text-To-Speech:
Universal: Using TtsUniversal to be able to configure the TTS provider dynamically and us it.
Single: Using TtsProviders.google, TtsProviders.microsoft, TtsProviders.amazon to use the single provider at a time.
Combine: Using TtsProviders.combine to combine all providers and get all voices at once.
Provider: Using TtsGoogle, TtsMicrosoft, TtsAmazon to get the most from provider's API.
Universal(Single)
To init configuration use:
//Do init once and run it before any other methodTtsUniversal.init(
provider: TtsProviders.amazon,
googleParams: InitParamsGoogle(apiKey: 'API-KEY'),
microsoftParams: InitParamsMicrosoft(
subscriptionKey: 'SUBSCRIPTION-KEY', region: 'eastus'),
amazonParams: InitParamsAmazon(
keyId: 'KEY-ID', accessKey: 'ACCESS-KEY', region: 'us-east-1'),
withLogs: true
);
To change provider use:
TtsUniversal.setProvider(TtsProviders.microsoft);
To get the list of all voices use:
//Get voicesfinal voicesResponse = awaitTtsUniversal.getVoices();
final voices = voicesResponse.voices;
//Print all available voicesprint(voices);
//Pick an English Voicefinal voice = voices
.where((element) => element.locale.code.startsWith("en-"))
.toList(growable: false)
.first;
To convert TTS and get audio use:
//Generate Audio for a textconst text = "Amazon, Microsoft and Google Text-to-Speech API are awesome";
final ttsParams = TtsParamsUniversal(
voice: voice,
audioFormat: AudioOutputFormatUniversal.mp3_64k,
text: text,
rate: 'slow', //optional
pitch: 'default'//optional
);
final ttsResponse = awaitTtsUniversal.convertTts(ttsParams);
//Get the audio bytes.final audioBytes = ttsResponse.audio.buffer.asByteData();
Universal(Combine)
To init configuration use:
//Do init once and run it before any other methodTtsUniversal.init(
provider: TtsProviders.combine,
googleParams: InitParamsGoogle(apiKey: 'API-KEY'),
microsoftParams: InitParamsMicrosoft(
subscriptionKey: 'SUBSCRIPTION-KEY', region: 'eastus'),
amazonParams: InitParamsAmazon(
keyId: 'KEY-ID', accessKey: 'ACCESS-KEY', region: 'us-east-1'),
withLogs: true
);
To change provider use:
TtsUniversal.setProvider(TtsProviders.combine);
To get the list of all voices use:
//Get voicesfinal voicesResponse = awaitTtsUniversal.getVoices();
final voices = voicesResponse.voices;
//Print all available voicesprint(voices);
//Pick an English Voicefinal voice = voices
.where((element) => element.locale.code.startsWith("en-"))
.toList(growable: false)
.first;
To convert TTS and get audio use:
//Generate Audio for a textconst text = "Amazon, Microsoft and Google Text-to-Speech API are awesome";
final ttsParams = TtsParamsUniversal(
voice: voice,
audioFormat: AudioOutputFormatUniversal.mp3_64k,
text: text,
rate: 'slow', //optional
pitch: 'default'//optional
);
final ttsResponse = awaitTtsUniversal.convertTts(ttsParams);
//Get the audio bytes.final audioBytes = ttsResponse.audio.buffer.asByteData();
Google
To init configuration use:
//Do init once and run it before any other methodTtsGoogle.init(
params: InitParamsGoogle(apiKey: "API-KEY"),
withLogs:true
);
To get the list of all voices use:
//Get voicesfinal voicesResponse = awaitTtsGoogle.getVoices();
final voices = voicesResponse.voices;
//Print all voicesprint(voices);
//Pick an English Voicefinal voice = voices
.where((element) => element.locale.code.startsWith("en-"))
.toList(growable: false)
.first;
To convert TTS and get audio use:
//Generate Audio for a textfinal text = '<speak>Google<break time="2s"> Speech Service Text-to-Speech API is awesome!</speak>';
TtsParamsGoogle ttsParams = TtsParamsGoogle(
voice: voice,
audioFormat: AudioOutputFormatGoogle.mp3,
text: text,
rate: 'slow', //optional
pitch: 'default'//optional
);
final ttsResponse = awaitTtsGoogle.convertTts(ttsParams);
//Get the audio bytes.final audioBytes = ttsResponse.audio.buffer.asByteData();
Microsoft
To init configuration use:
//Do init once and run it before any other methodTtsMicrosoft.init(
params: InitParamsMicrosoft(
subscriptionKey: "SUBSCRIPTION-KEY", region: "eastus"),
withLogs: true
);
To get the list of all voices use:
//Get voicesfinal voicesResponse = awaitTtsMicrosoft.getVoices();
final voices = voicesResponse.voices;
//Print all voicesprint(voices);
//Pick an English Voicefinal voice = voices
.where((element) => element.locale.code.startsWith("en-"))
.toList(growable: false)
.first;
To convert TTS and get audio use:
//Generate Audio for a textfinal text = '<speak>Microsoft<break time="2s"> Speech Service Text-to-Speech API is awesome!</speak>';
TtsParamsMicrosoft ttsParams = TtsParamsMicrosoft(
voice: voice,
audioFormat: AudioOutputFormatMicrosoft.audio48Khz192kBitrateMonoMp3,
text: text,
rate: 'slow', //optional
pitch: 'default'//optional
);
final ttsResponse = awaitTtsMicrosoft.convertTts(ttsParams);
//Get the audio bytes.final audioBytes = ttsResponse.audio.buffer.asByteData();
Amazon
To init configuration use:
//Do init once and run it before any other methodTtsAmazon.init(
params: InitParamsAmazon(
keyId: 'KEY-ID',
accessKey: 'ACCESS-KEY',
region: 'us-east-1'
),
withLogs: true
);
To get the list of all voices use:
//Get voicesfinal voicesResponse = awaitTtsAmazon.getVoices();
final voices = voicesResponse.voices;
//Print all voicesprint(voices);
//Pick an English Voicefinal voice = voices
.where((element) => element.locale.code.startsWith("en-"))
.toList(growable: false)
.first;
To convert TTS and get audio use:
//Generate Audio for a textfinal text = '<speak>Amazon<break time="2s"> Speech Service Text-to-Speech API is awesome!</speak>';
TtsParamsAmazon ttsParams = TtsParamsAmazon(
voice: voice,
audioFormat: AudioOutputFormatAmazon.audio48Khz192kBitrateMonoMp3,
text: text,
rate: 'slow', //optional
pitch: 'default'//optional
);
final ttsResponse = awaitTtsAmazon.convertTts(ttsParams);
//Get the audio bytes.final audioBytes = ttsResponse.audio.buffer.asByteData();
Notes
There are things you should take care of:
Securing of your API keys and credentials, they could be extracted from your mobile or web app.
Sometimes Amazon Polly is not working in emulator, so you could get 403 error.
For fixing SSML/XML before passing it to TTS Params, you could use
the xml package's,
methods XmlDocument.parse(ssml).toXmlString().
Audio has uniform format for all providers, it is Uint8List that you could use to play it or save
it to file.