-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a76774f
Showing
13 changed files
with
456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/build/ | ||
/bundle/ | ||
/.idea | ||
/.gradle/ | ||
/gradle/ | ||
/gradlew | ||
/gradlew.* | ||
|
||
/*.phpintel | ||
|
||
/package.hub.yml | ||
/package-lock.php.yml | ||
/vendor/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## Changelog | ||
|
||
``` | ||
--- 1.1 --- | ||
[Add] Class Yandex | ||
[Add] Class BaseQuery | ||
[Add] PHPDoc hints | ||
[Fix] Auto-detect language | ||
[Del] Function Translate->query() | ||
[Change] Package name | ||
[Rewrite] All code | ||
``` | ||
|
||
## Install package via jppm | ||
|
||
```bash | ||
jppm add windows@git+https://github.com/GIGNIGHT/jphp-yandex-ext | ||
``` | ||
|
||
## Build bundle | ||
|
||
``` | ||
jppm bundle:build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Yandex | ||
version: 1.1 | ||
description: Yandex Package | ||
|
||
plugins: | ||
- Hub | ||
- Doc | ||
|
||
sources: | ||
- src | ||
|
||
doc: | ||
stub-dirs: ['./src/'] | ||
langs: {en: English, ru: Русский} | ||
|
||
devDeps: | ||
dn-bundle-plugin: '*' | ||
|
||
config: | ||
ignore: | ||
- /*.iml | ||
- /.git/** | ||
- /package.hub.yml | ||
- /.gitignore | ||
- /gradle/** | ||
- /**.phpintel | ||
- /bundle/** | ||
- /src-bundle/** | ||
- /build/** | ||
- /vendor/** | ||
- /jars/** | ||
- /src-jvm/** | ||
- /.gitignore | ||
- /**.gradle | ||
- /gradlew | ||
- /gradlew.** | ||
|
||
develnext-bundle: | ||
version: 1.1 | ||
name: Yandex | ||
description: Yandex Package | ||
author: GIGNIGHT | ||
icon: "develnext/bundle/yandex/yandex.png" | ||
group: "system" | ||
class: "develnext\\bundle\\yandex\\YandexBundle" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = 'dn-yandex-bundle' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
namespace develnext\bundle\yandex; | ||
|
||
use ide\bundle\AbstractBundle; | ||
use ide\bundle\AbstractJarBundle; | ||
use ide\project\Project; | ||
|
||
/** | ||
* Class YandexBundle | ||
* | ||
* @author GIGNIGHT | ||
* @link gignight.ru / vk.com/gignight1337 | ||
*/ | ||
class YandexBundle extends AbstractJarBundle | ||
{ | ||
public function onAdd(Project $project, AbstractBundle $owner = null) | ||
{ | ||
parent::onAdd($project, $owner); | ||
} | ||
|
||
public function onRemove(Project $project, AbstractBundle $owner = null) | ||
{ | ||
parent::onRemove($project, $owner); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<ul> | ||
<li style="line-height: 19px; color: gray;"><font face="monospace" style="line-height: 19px;"><span style="line-height: 19px;"><b style="line-height: 19px;">Yandex\Translate (переводчик)</b></span></font></li><li style="line-height: 19px; color: gray;"><b style="line-height: 19px; font-family: monospace;">Yandex\SpeechKit (синтезатор речи)</b></li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Yandex\Exception; | ||
|
||
/** | ||
* Class BaseException | ||
* | ||
* @author GIGNIGHT | ||
* @link gignight.ru / vk.com/gignight1337 | ||
*/ | ||
abstract class BaseException extends \Exception | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Yandex\Exception; | ||
|
||
/** | ||
* Class TranslateException | ||
* | ||
* @author GIGNIGHT | ||
* @link gignight.ru / vk.com/gignight1337 | ||
*/ | ||
class TranslateException extends BaseException | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $errorMessage = | ||
[ | ||
401 => 'Неправильный API-ключ', | ||
402 => 'API-ключ заблокирован', | ||
404 => 'Превышено суточное ограничение на объем переведенного текста', | ||
413 => 'Превышен максимально допустимый размер текста', | ||
422 => 'Текст не может быть переведен', | ||
501 => 'Указанное направление перевода не поддерживается' | ||
]; | ||
|
||
public function __construct($errorCode) | ||
{ | ||
parent::__construct($this->errorMessage[$errorCode], $errorCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
namespace Yandex; | ||
|
||
use Yandex\classes\Yandex; | ||
use script\MediaPlayerScript; | ||
|
||
/** | ||
* Class Yandex SpeechKit Cloud | ||
* | ||
* @author GIGNIGHT | ||
* @link gignight.ru / vk.com/gignight1337 | ||
*/ | ||
class SpeechKit extends BaseQuery | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $key = ''; | ||
|
||
/** | ||
* Голос синтезированной речи | ||
* jane | oksana | alyss | omazh | zahar | ermil | ||
* | ||
* @var string | ||
*/ | ||
public $speaker = 'zahar'; | ||
|
||
/** | ||
* Расширение синтезируемого файла | ||
* mp3 | wav | opus | ||
* | ||
* @var string | ||
*/ | ||
public $format = 'mp3'; | ||
|
||
/** | ||
* Язык текста | ||
* ru-RU | en-US | uk-UK | tr-TR | ||
* | ||
* @var string | ||
*/ | ||
public $language = 'ru-RU'; | ||
|
||
/** | ||
* Скорость воспроизведения | ||
* Max — 3.0 | ||
* Min — 0.1 | ||
* Normal — 1.0 | ||
* | ||
* @var double | ||
*/ | ||
public $speed = 1.0; | ||
|
||
/** | ||
* Эмоциональная окраска голоса | ||
* good — радостный | ||
* evil — раздраженный | ||
* neutral — нейтральный | ||
* | ||
* @var string | ||
*/ | ||
public $emotion = 'good'; | ||
|
||
/** | ||
* Частота дискретизации и битрейт синтезируемого PCM-аудио | ||
* hi — частота дискретизации 48 кГц и битрейт 768 кб/c | ||
* lo — частота дискретизации 8 кГц и битрейт 128 кб/c | ||
* | ||
* @var string | ||
*/ | ||
public $quality = null; | ||
|
||
/** | ||
* Автоопределение языка | ||
* | ||
* @var bool | ||
*/ | ||
public $autoDetect = true; | ||
|
||
/** | ||
* @var MediaPlayerScript | ||
*/ | ||
protected $media; | ||
|
||
public function __construct($key) | ||
{ | ||
$this->api->setUrl(Yandex::SPEECHKIT_URL); | ||
$this->key = $key; | ||
$this->media = new MediaPlayerScript(); | ||
} | ||
|
||
/** | ||
* Воспроизвести | ||
* | ||
* @param string $text | ||
*/ | ||
public function speak($text) | ||
{ | ||
$params = | ||
[ | ||
'key' => $this->key, 'text' => urlencode($text), | ||
'format' => $this->format, 'quality' => $this->quality, | ||
'lang' => $this->language, 'speaker' => $this->speaker, | ||
'speed' => $this->speed, 'emotion' => $this->emotion | ||
]; | ||
$speak = $this->api->query('generate', $params)->body(); | ||
|
||
/*if ($this->autoDetect) | ||
{ | ||
$detect = new Translate()->detect($text); | ||
$this->language = $detect . '-' . strtoupper($detect); | ||
}*/ | ||
|
||
$file = sprintf("%s\\%s.%s", $_ENV['TEMP'], md5('yandex_speech'), $this->format); | ||
file_put_contents($file, $speak); | ||
$this->media->open($file); $this->media->play(); | ||
} | ||
} |
Oops, something went wrong.