{"id":15025774,"url":"https://github.com/ginopane/phpolyglot","last_synced_at":"2025-04-09T20:04:52.141Z","repository":{"id":62510811,"uuid":"110734193","full_name":"GinoPane/PHPolyglot","owner":"GinoPane","description":"PHP package for translation, spelling correction and text-to-speech (TTS) synthesis using external APIs","archived":false,"fork":false,"pushed_at":"2018-03-03T21:02:29.000Z","size":254,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T20:04:35.986Z","etag":null,"topics":["ibm-watson","php-library","php71","spelling","text-to-speech","translation","tts","yandex-translate"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GinoPane.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-14T19:20:02.000Z","updated_at":"2022-06-28T12:20:10.000Z","dependencies_parsed_at":"2022-11-02T13:16:43.980Z","dependency_job_id":null,"html_url":"https://github.com/GinoPane/PHPolyglot","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GinoPane%2FPHPolyglot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GinoPane%2FPHPolyglot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GinoPane%2FPHPolyglot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GinoPane%2FPHPolyglot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GinoPane","download_url":"https://codeload.github.com/GinoPane/PHPolyglot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103868,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ibm-watson","php-library","php71","spelling","text-to-speech","translation","tts","yandex-translate"],"created_at":"2024-09-24T20:02:59.558Z","updated_at":"2025-04-09T20:04:52.112Z","avatar_url":"https://github.com/GinoPane.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"PHPolyglot\n==========\n\n[![Latest Stable Version](https://poser.pugx.org/gino-pane/phpolyglot/v/stable)](https://packagist.org/packages/gino-pane/phpolyglot)\n[![Build Status](https://travis-ci.org/GinoPane/PHPolyglot.svg?branch=master)](https://travis-ci.org/GinoPane/PHPolyglot)\n[![Maintainability](https://api.codeclimate.com/v1/badges/b1e2b6042612f67f7e13/maintainability)](https://codeclimate.com/github/GinoPane/PHPolyglot/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/b1e2b6042612f67f7e13/test_coverage)](https://codeclimate.com/github/GinoPane/PHPolyglot/test_coverage)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/GinoPane/phpolyglot/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/GinoPane/phpolyglot/?branch=master)\n[![License](https://poser.pugx.org/gino-pane/phpolyglot/license)](https://packagist.org/packages/gino-pane/phpolyglot)\n[![Total Downloads](https://poser.pugx.org/gino-pane/phpolyglot/downloads)](https://packagist.org/packages/gino-pane/phpolyglot)\n\nCombining and featuring different APIs for language translation, dictionary lookup, spelling correction and speech synthesis (TTS) in an easy to use and extend way.\n\nTable of Contents\n-----------------\n* [General Information](#phpolyglot)\n    * [Features](#features)\n    * [Requirements](#requirements)\n    * [Installation](#installation)\n* [Basic Usage](#basic-usage)\n    * [Translation](#translation)\n        * [Yandex Translate API](#yandex-translate-api)\n    * [Dictionary Lookup](#dictionary-lookup)\n        * [Yandex Dictionary API](#yandex-dictionary-api)\n    * [Spelling Check](#spelling-check)\n        * [Yandex Speller API](#yandex-speller-api)\n    * [Speech Synthesis](#speech-synthesis)\n        * [IBM Watson Text-to-Speech](#ibm-watson-text-to-speech)\n* [Possible ToDos](#possible-todos)\n* [Useful Tools](#useful-tools)\n    * [Running Tests](#running-tests)\n    * [Code Sniffer Tool](#code-sniffer-tool)\n    * [Code Auto-fixer](#code-auto-fixer)\n    * [Building Docs](#building-docs)\n* [Changelog](#changelog)\n* [Contributing](#contributing)\n* [License](#license)\n* [Notes](#notes)    \n\nFeatures\n--------\n\n* provides an easy-to-use way to utilise different language-related APIs for translation, grammar correction, TTS, etc.;\n* 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);\n* open or free (possibly with limitations) APIs are preferred;\n* language codes must be [ISO-639](https://www.loc.gov/standards/iso639-2/php/code_list.php) compatible (alpha-2 or alpha-3 if there's no alpha-2);\n* third-party APIs may contain their own limitations or licensing requirements (see [License](#license))\n\nRequirements\n------------\n\n* PHP \u003e= 7.1;\n* credentials for Yandex Translate API, Yandex Dictionary API and IBM Watson API (depending on what you are going to use).\n\nInstallation\n------------\n```\ncomposer require gino-pane/phpolyglot\n```\n\nCreate 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.\n\n\u003e In order to run examples from [examples](https://github.com/GinoPane/PHPolyglot/blob/master/examples) directory you have to specify your own valid API credentials.\n    \nBasic Usage\n===========\n\nThe package contains a plenty of ready-to-use examples in [examples](https://github.com/GinoPane/PHPolyglot/blob/master/examples) directory.\nAll endpoints either return a valid response or throws a relevant exception.\nAll APIs are configured through [config.php](https://github.com/GinoPane/PHPolyglot/blob/master/config.php) file which contains the default API classes mapping. Support of dynamic configs was added in [1.1.0](https://github.com/GinoPane/PHPolyglot/releases/tag/v1.1.0) update:\n\n```php\n$phpolyglot = new PHPolyglot($config, $env);\n```\n\nThis allows you to pass your own configuration values if you don't want to rely on those that are stored in configuration files.\n\nTranslation\n-----------\n\nThere are two endpoints. For a single string:\n\n```php\nfunction translate(string $text, string $languageTo, string $languageFrom = ''): TranslateResponse\n```\n\nand for multiple strings:\n\n```php\nfunction translateBulk(array $text, string $languageTo, string $languageFrom = ''): TranslateResponse\n```\n\nAs a minimum example you can pass text and language to translate into (source language will be detected by API):\n\n```php\n$response = (new PHPolyglot())-\u003etranslate('Hello world', 'it')-\u003egetTranslations(); // [ 0 =\u003e Ciao mondo ]\n```\n\n`TranslateResponse` has `getTranslations` method which returns an array of translations.\n\nSupported languages may vary depending on third-party API.\n\n### Yandex Translate API\n\nPlease check the [list of supported languages](https://tech.yandex.com/translate/doc/dg/concepts/api-overview-docpage/#languages).\n[Yandex Translate API](https://tech.yandex.com/translate/doc/dg/concepts/api-overview-docpage/) is free to use with [limitations](https://translate.yandex.com/developers/prices) (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.\nIn order to use the API you need to get the valid [API key](https://tech.yandex.com/keys/?service=trnsl).\n\nDictionary Lookup\n-----------------\n\nThere is a single endpoint, which can be used in two different forms.\n\nFor a lookup within the same language (get word forms):\n\n```php\nfunction lookup(string $text, string $languageFrom): DictionaryResponse\n```\n\nand for translation-with-lookup (get multiple translations and additional information including word forms, examples, meanings, synonyms, transcription, etc.):\n\n```php\nfunction lookup(string $text, string $languageFrom, string $languageTo): DictionaryResponse\n```\n\nAs a minimum example you can pass text and its source language:\n\n```php\n$response = (new PHPolyglot)-\u003elookup('Hello', 'en)-\u003egetEntries();\n\n$synonyms = implode(\", \", $response[0]-\u003egetSynonyms());\n\n$output = \u003c\u003c\u003cTEXT\nInitial word: {$response[0]-\u003egetTextFrom()}\n\nPart of speech: {$response[0]-\u003egetPosFrom()}\nTranscription: {$response[0]-\u003egetTranscription()}\n\nMain alternative: {$response[0]-\u003egetTextTo()}\nSynonyms: {$synonyms}\nTEXT\n\necho $output\n\n/**\nInitial word: hello\n  \nPart of speech: noun\nTranscription: ˈheˈləʊ\n\nMain alternative: hi\nSynonyms: hallo, salut\n*/\n```\n\nSupported languages may vary depending on third-party API.\n\n### Yandex Dictionary API\n\nPlease check the [list of supported languages](https://tech.yandex.com/dictionary/doc/dg/reference/getLangs-docpage/).\n[Yandex Dictionary API](https://tech.yandex.com/dictionary/doc/dg/concepts/api-overview-docpage/) is free to use with [limitations](https://yandex.com/legal/dictionary_api/?lang=en) (up to 10 000 references per day).\nIn order to use the API you need to get the valid [API key](https://tech.yandex.com/keys/?service=dict).\n\n\nSpelling Check\n--------------\n\nThere are two endpoints. For a single string:\n\n```php\nfunction spellCheck(string $text, string $languageFrom = ''): SpellCheckResponse\n```\n\nand for multiple strings:\n\n```php\nfunction spellCheckBulk(array $texts, string $languageFrom = ''): SpellCheckResponse\n```\n\nAs a minimum example you can pass only a text to check:\n\n```php\n$corrections = $phpolyglot-\u003espellCheckText('Helo werld', $languageFrom)-\u003egetCorrections();\n\n/**\narray(1) {\n  [0] =\u003e\n  array(2) {\n    'Helo' =\u003e\n    array(1) {\n      [0] =\u003e\n      string(5) \"Hello\"\n    }\n    'werld' =\u003e\n    array(1) {\n      [0] =\u003e\n      string(5) \"world\"\n    }\n  }\n}\n*/\n\n```\n\nSupported languages may vary depending on third-party API.\n\n### Yandex Speller API\n\nPlease check the [list of supported languages](https://tech.yandex.ru/speller/doc/dg/concepts/speller-overview-docpage/) (basically, only English, Russian and Ukrainian are supported at the moment).\n[Yandex Speller API](https://tech.yandex.ru/speller/doc/dg/concepts/api-overview-docpage/) is free to use with [limitations](https://yandex.ru/legal/speller_api/) (up to 10 000 calls/10 000 000 characters per day). No keys are required.\n\nSpeech Synthesis\n----------------\n\nThe main endpoint is `PHPolyglot`'s `speak` method:\n\n```php\npublic function speak(\n    string $text,\n    string $languageFrom,\n    string $audioFormat = TtsAudioFormat::AUDIO_MP3,\n    array $additionalData = []\n): TtsResponse\n``` \n    \nOnly two parameters are required - text for synthesis `$text` and its source language `$languageFrom`. \n\nOptional 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.).\n\nThe list of audio formats which are currently recognized:\n\n* TtsAudioFormat::AUDIO_BASIC\n* TtsAudioFormat::AUDIO_FLAC\n* TtsAudioFormat::AUDIO_L16\n* TtsAudioFormat::AUDIO_MP3\n* TtsAudioFormat::AUDIO_MPEG\n* TtsAudioFormat::AUDIO_MULAW\n* TtsAudioFormat::AUDIO_OGG\n* TtsAudioFormat::AUDIO_WAV\n* TtsAudioFormat::AUDIO_WEBM\n\nPlease note that not all of them may be supported by your API of choice.\n\nThe 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):\n\n```php\nfunction storeFile(string $fileName = '', string $extension = '', string $directory = ''): string\n```\n\nBy 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.\n\n```php\n(new PHPolyglot())-\u003espeak('Hello world', 'en')-\u003estoreFile(); // stores 3e25960a79dbc69b674cd4ec67a72c62.mp3\n```\n\n### IBM Watson Text-to-Speech\n\nPlease check the [list of supported languages and voices](https://console.bluemix.net/docs/services/text-to-speech/http.html#voices).\nIBM Watson TTS requires API credentials for authorization. Create your TTS project [there](https://www.ibm.com/watson/services/text-to-speech/) and get your API-specific credentials. API is free to use with limitations (up to 10 000 characters per month).\n\nPossible ToDos\n==============\n* transcribe words;\n* get synonyms, antonyms, derivatives;\n* detect text language;\n* add more configuration flexibility (choose API based on config constraints, like different APIs for different languages).\n    \nUseful Tools\n============\n\nRunning Tests:\n--------------\n\n    php vendor/bin/phpunit\n \n or \n \n    composer test\n\nCode Sniffer Tool:\n------------------\n\n    php vendor/bin/phpcs --standard=PSR2 src/\n \n or\n \n    composer psr2check\n\nCode Auto-fixer:\n----------------\n\n    php vendor/bin/phpcbf --standard=PSR2 src/ \n    \n or\n \n    composer psr2autofix\n \n \nBuilding Docs:\n-------------\n\n    php vendor/bin/phpdoc -d \"src\" -t \"docs\"\n \n or \n \n    composer docs\n    \nChangelog\n=========\n\nTo keep track, please refer to [CHANGELOG.md](https://github.com/GinoPane/PHPolyglot/blob/master/CHANGELOG.md).\n\nContributing\n============\n\n1. Fork it;\n2. Create your feature branch (git checkout -b my-new-feature);\n3. Make your changes;\n4. Run the tests, adding new ones for your own code if necessary (phpunit);\n5. Commit your changes (git commit -am 'Added some feature');\n6. Push to the branch (git push origin my-new-feature);\n7. Create new pull request.\n\nAlso please refer to [CONTRIBUTING.md](https://github.com/GinoPane/PHPolyglot/blob/master/CONTRIBUTING.md).\n\nLicense\n=======\n\nPlease refer to [LICENSE](https://github.com/GinoPane/PHPolyglot/blob/master/LICENSE).\n\u003e The [PHPolyglot](https://github.com/GinoPane/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.\n\nNotes\n=====\n\nPowered by [composer-package-template](https://github.com/GinoPane/composer-package-template) and [PHP Nano Rest](https://github.com/GinoPane/php-nano-rest).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fginopane%2Fphpolyglot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fginopane%2Fphpolyglot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fginopane%2Fphpolyglot/lists"}