定制 zloesabo/speechkit-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zloesabo/speechkit-php

Composer 安装命令:

composer require zloesabo/speechkit-php

包简介

Yandex SpeechKit for PHP

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage

Yandex SpeechKit PHP library.

Installation

SpeechKit uses Composer, please checkout the composer website for more information.

Add SpeechKit in your composer.json and you can go ahead:

composer require zloesabo/speechkit-php

SpeechKit follows the PSR-4 convention names for its classes, which means you can easily integrate SpeechKit classes loading in your own autoloader.

For users of old version

Usage of previous version is strongly discouraged as it lacked concept and testing. However, if you sure you want to use previous version of library, require it with composer require zloesabo/speechkit-php:~1.0

Usage

Simple

// Include dependencies installed with composer
require 'vendor/autoload.php';

use SpeechKit\Response\HypothesesList;
use SpeechKit\Response\Hypothesis;
use SpeechKit\Speech\SpeechContent;
use SpeechKit\SpeechKit;

$key = 'your-key-here';

$speechKit = new SpeechKit($key);

//It can be any type of stream. File, string, instance of StreamInterface, etc.
$source = fopen(__DIR__.'/some/path/to/file.mp3', 'r');

$speech = new SpeechContent($source);

//Defaults will be used: mp3, general topic, russian language
/** @var HypothesesList $result */
$result = $speechKit->recognize($speech);

/** @var Hypothesis $hyphotesis */
foreach ($result as $hyphotesis) {
    echo sprintf(
        'Confidence: %.2f Content: %s',
        $hyphotesis->getConfidence(),
        $hyphotesis->getContent()
    ), PHP_EOL;
}

Advanced

require 'vendor/autoload.php';

use SpeechKit\Client\Curl;
use SpeechKit\Response\HypothesesList;
use SpeechKit\Response\Hypothesis;
use SpeechKit\ResponseParser\SimpleXML;
use SpeechKit\Speech\SpeechContent;
use SpeechKit\Speech\SpeechContentInterface;
use SpeechKit\SpeechKit;
use SpeechKit\Uploader\Uploader;
use SpeechKit\Uploader\UrlGenerator;

$key = 'your-key-here';

$urlGenerator = new UrlGenerator($key);

//You could use any type of client which implements ClientInterface
$client = new Curl();
$uploader = new Uploader($urlGenerator, $client);

//You could use any type of parser which implements ResponseParserInterface
$responseParser = new SimpleXML();

$speechKit = new SpeechKit($key, $uploader, $responseParser);

$source = fopen(__DIR__.'/some/path/to/file.mp3', 'r');
$speech = new SpeechContent($source);

//These settings are default, so you can skip setting them
$speech->setContentType(SpeechContentInterface::CONTENT_MP3);
$speech->setTopic(SpeechContentInterface::TOPIC_GENERAL);
$speech->setLang(SpeechContentInterface::LANG_RU);
$speech->setUuid(bin2hex(openssl_random_pseudo_bytes(16)));

/** @var HypothesesList $result */
$result = $speechKit->recognize($speech);

/** @var Hypothesis $hyphotesis */
foreach ($result as $hyphotesis) {
    echo sprintf(
        'Confidence: %.2f Content: %s',
        $hyphotesis->getConfidence(),
        $hyphotesis->getContent()
    ), PHP_EOL;
}

统计信息

  • 总下载量: 1.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-08-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固