Реч в текст - Speech to text PHP

Публикувано: 19.01.15, 22:50:36 | Автор: ArMeN | Видяна: 1380 | Редактирано: 19.01.15, 23:18:23

Реч в текст - Speech to text
Вие говорите, а думите се превръщат в текст
Получаване на API Keys
FLAC.zip
Реч в текст - Speech to text PHP<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Speech to text</title>
</head>
<body>
<?
$file_to_upload = array('myfile'=>'@current.flac');

$lang = 'ru-ru';
$key = 'API Keys API Keys API Keys API Keys';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/speech-api/v2/recognize?output=json&lang='.$lang.'&key='.$key);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: audio/x-flac; rate=44100;'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $file_to_upload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);

// Покачать весь ответ гугла
//echo '
result='.$result."
";

// По не выясненным пока причинам, в версии V2 первый ответ всегда пустой. Берем второй.
$result_arr = explode("\n", $result); $result = $result_arr[1];
// Google возвращает JSON, поэтому парсим стандартной функцией. Доступна в PHP 5.2
$json_array = json_decode($result, true);
$Speech_to_text = $json_array['result'][0]['alternative'][0]['transcript'];
echo('
Speech to text: '.$Speech_to_text);
?>
</body>
</html>

Не сте влезли в акаунта си за да коментирате.


 

Няма коментари.