Convert written text into natural-sounding audio in a variety of languages and voices.
This package use IBM Watson Text To Speech service.
Intall library in PHP project using composer
composer require tbetool/ibm-watson-tts
After installing the library, create WatsonTts
object
$watson = new WatsonTts(
'watson_username',
'watson_password',
'watson_url'
);
Watson username, password, url
can be obtained by creating an instance of service. For more detail follow Getting Started Guide.
Set absolute path of the directory where to save the output. You don't need to provide a file name as it will be auto generated.
$path = '/aboslute/path/to/directory';
$watson->setOutputPath($path);
Pass text to convert to speech.
$file = $watson->tts('Hello World');
This will return the absolute path of the file created if text to speech conversion is successful, otherwise will throw Exception.
Every function throws an Exception in case of any error/issue. Bind the code block within try-catch
block to catch any exception occurred.
Ex:
try {
$watson->setAudioFormat('mp3');
} catch (Exception $exception) {
echo $exception->getMessage();
}
will throw and exception Not a valid audio format. Allowed formats: wav, ogg
as mp3
audio format is not supported as of now
$watson->setAudioFormat('wav');
allowed formats: wav
, ogg
default: wav
$watson->setLanguage('en-US');
allowed languages: See List
default: en-US
$watson->setVoice('MichaelVoice');
allowed voices: See List
default: MichaelVoice
list of supported language and voice strings
Name | language | voice | gender | description |
---|---|---|---|---|
es-LA_SofiaVoice | es-LA | SofiaVoice | female | Sofia: Latin American Spanish (español latinoamericano) female voice. |
pt-BR_IsabelaVoice | pt-BR | IsabelaVoice | female | Isabela: Brazilian Portuguese (português brasileiro) female voice. |
en-GB_KateVoice | en-GB | KateVoice | female | Kate: British English female voice. |
de-DE_BirgitVoice | de-DE | BirgitVoice | female | Birgit: Standard German of Germany (Standarddeutsch) female voice. |
en-US_AllisonVoice | en-US | AllisonVoice | female | Allison: American English female voice. |
fr-FR_ReneeVoice | fr-FR | ReneeVoice | female | Renee: French (français) female voice. |
it-IT_FrancescaVoice | it-IT | FrancescaVoice | female | Francesca: Italian (italiano) female voice. |
es-ES_LauraVoice | es-ES | LauraVoice | female | Laura: Castilian Spanish (español castellano) female voice. |
ja-JP_EmiVoice | ja-JP | EmiVoice | female | Emi: Japanese (日本語) female voice. |
es-ES_EnriqueVoice | es-ES | EnriqueVoice | male | Enrique: Castilian Spanish (español castellano) male voice. |
de-DE_DieterVoice | de-DE | DieterVoice | male | Dieter: Standard German of Germany (Standarddeutsch) male voice. |
en-US_LisaVoice | en-US | LisaVoice | female | Lisa: American English female voice. |
en-US_MichaelVoice | en-US | MichaelVoice | male | Michael: American English male voice. |
es-US_SofiaVoice | es-US | SofiaVoice | female | Sofia: North American Spanish (español norteamericano) female voice. |
If you found any bug, create an issue.
Something is missing?
Fork
the repositroy- Make your contribution
- make a
pull request