Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Quick start Speech to text on Microsoft Azure with PHP

More than 1 year has passed since last update.

Why

There is no sample code with PHP on official document

Environment

PHP 7.1.8
Zend Engine v3.1.0

Code

<?php
$language = 'en-US'
$url = 'https://westus.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language='.$language;
$curl = curl_init();

$header = [
    'Ocp-Apim-Subscription-Key: {your key}',
    'Content-Type: audio/wav; codec=audio/pcm; samplerate=16000',
    'Accept: application/json'
];

curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, file_get_contents('test_audio.wav'));

$response = curl_exec($curl);
curl_close($curl);

/* for debug
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
$info = curl_getinfo($curl);
var_dump($info);
*/

var_dump($response);                         
osk_kamui
色々やってます
rarejob
明治神宮にあるオンライン英会話サービスを提供するベンチャー
https://www.rarejob.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away