Download the PHP package gino-pane/phpolyglot without Composer
On this page you can find all versions of the php package gino-pane/phpolyglot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gino-pane/phpolyglot
More information about gino-pane/phpolyglot
Files in gino-pane/phpolyglot
Package phpolyglot
Short Description PHP package for translation, spelling correction and text-to-speech (TTS) synthesis using external APIs
License MIT
Homepage http://github.com/GinoPane/PHPolyglot
Informations about the package phpolyglot
PHPolyglot
Combining and featuring different APIs for language translation, dictionary lookup, spelling correction and speech synthesis (TTS) in an easy to use and extend way.
Table of Contents
- General Information
- Features
- Requirements
- Installation
- Basic Usage
- Translation
- Yandex Translate API
- Dictionary Lookup
- Yandex Dictionary API
- Spelling Check
- Yandex Speller API
- Speech Synthesis
- IBM Watson Text-to-Speech
- Translation
- Possible ToDos
- Useful Tools
- Running Tests
- Code Sniffer Tool
- Code Auto-fixer
- Building Docs
- Changelog
- Contributing
- License
- Notes
Features
- provides an easy-to-use way to utilise different language-related APIs for translation, grammar correction, TTS, etc.;
- custom APIs can be easily added, because the package heavily relies on implementation of different interfaces, therefore it is easy to plug-in (pull requests are appreciated);
- open or free (possibly with limitations) APIs are preferred;
- language codes must be ISO-639 compatible (alpha-2 or alpha-3 if there's no alpha-2);
- third-party APIs may contain their own limitations or licensing requirements (see License)
Requirements
- PHP >= 7.1;
- credentials for Yandex Translate API, Yandex Dictionary API and IBM Watson API (depending on what you are going to use).
Installation
Create a copy of .env.example
file, name it .env
and put your own API credentials in it. File contains links to pages which may be related to required credentials.
In order to run examples from examples directory you have to specify your own valid API credentials.
Basic Usage
The package contains a plenty of ready-to-use examples in examples directory. All endpoints either return a valid response or throws a relevant exception. All APIs are configured through config.php file which contains the default API classes mapping. Support of dynamic configs was added in 1.1.0 update:
This allows you to pass your own configuration values if you don't want to rely on those that are stored in configuration files.
Translation
There are two endpoints. For a single string:
and for multiple strings:
As a minimum example you can pass text and language to translate into (source language will be detected by API):
TranslateResponse
has getTranslations
method which returns an array of translations.
Supported languages may vary depending on third-party API.
Yandex Translate API
Please check the list of supported languages. Yandex Translate API is free to use with limitations (1000 000 characters per day, up to 10 000 000 per month). If you want you can get a paid plan of course. The API won't let you to get into paid plan automatically, it will simply return an error when the limit is reached. In order to use the API you need to get the valid API key.
Dictionary Lookup
There is a single endpoint, which can be used in two different forms.
For a lookup within the same language (get word forms):
and for translation-with-lookup (get multiple translations and additional information including word forms, examples, meanings, synonyms, transcription, etc.):
As a minimum example you can pass text and its source language:
Supported languages may vary depending on third-party API.
Yandex Dictionary API
Please check the list of supported languages. Yandex Dictionary API is free to use with limitations (up to 10 000 references per day). In order to use the API you need to get the valid API key.
Spelling Check
There are two endpoints. For a single string:
and for multiple strings:
As a minimum example you can pass only a text to check:
Supported languages may vary depending on third-party API.
Yandex Speller API
Please check the list of supported languages (basically, only English, Russian and Ukrainian are supported at the moment). Yandex Speller API is free to use with limitations (up to 10 000 calls/10 000 000 characters per day). No keys are required.
Speech Synthesis
The main endpoint is PHPolyglot
's speak
method:
Only two parameters are required - text for synthesis $text
and its source language $languageFrom
.
Optional parameters $audioFormat
and $additionalData
may be omitted. Audio format allows to explicitly specify the required audio format of returned audio. Additional data allows to set API specific parameters for more precise results (voice, pitch, speed, etc.).
The list of audio formats which are currently recognized:
- TtsAudioFormat::AUDIO_BASIC
- TtsAudioFormat::AUDIO_FLAC
- TtsAudioFormat::AUDIO_L16
- TtsAudioFormat::AUDIO_MP3
- TtsAudioFormat::AUDIO_MPEG
- TtsAudioFormat::AUDIO_MULAW
- TtsAudioFormat::AUDIO_OGG
- TtsAudioFormat::AUDIO_WAV
- TtsAudioFormat::AUDIO_WEBM
Please note that not all of them may be supported by your API of choice.
The TTS method returns TtsResponse
which has storeFile
method to store generated file with required name and extension into the specified directory (or by using default values):
By default the file name is a simple md5
hash of $text
that was used for TTS, $extension
is being populated based on content-type
header (at least, for IBM Watson API), $directory
is based on config setting.
IBM Watson Text-to-Speech
Please check the list of supported languages and voices. IBM Watson TTS requires API credentials for authorization. Create your TTS project there and get your API-specific credentials. API is free to use with limitations (up to 10 000 characters per month).
Possible ToDos
- transcribe words;
- get synonyms, antonyms, derivatives;
- detect text language;
- add more configuration flexibility (choose API based on config constraints, like different APIs for different languages).
Useful Tools
Running Tests:
php vendor/bin/phpunit
or
composer test
Code Sniffer Tool:
php vendor/bin/phpcs --standard=PSR2 src/
or
composer psr2check
Code Auto-fixer:
php vendor/bin/phpcbf --standard=PSR2 src/
or
composer psr2autofix
Building Docs:
php vendor/bin/phpdoc -d "src" -t "docs"
or
composer docs
Changelog
To keep track, please refer to CHANGELOG.md.
Contributing
- Fork it;
- Create your feature branch (git checkout -b my-new-feature);
- Make your changes;
- Run the tests, adding new ones for your own code if necessary (phpunit);
- Commit your changes (git commit -am 'Added some feature');
- Push to the branch (git push origin my-new-feature);
- Create new pull request.
Also please refer to CONTRIBUTING.md.
License
Please refer to LICENSE.
The PHPolyglot does not own any of results that APIs may return. Also, APIs may have their own rules about data usage, so beware of them when you use them.
Notes
Powered by composer-package-template and PHP Nano Rest.