【发布时间】:2018-01-22 08:13:45
【问题描述】:
我正在开发一个包含音频到文本页面的网站,我正在尝试使用来自 Google 的 API,但它似乎无限加载并给我一个超时,在 Google 控制台上它向我显示已发出请求所以我猜它来自我的渲染(我正在 Symfony 上开发)
这是我的功能
public function transcribeAction($audioFile = 'C:\Users\Poste3\Downloads\rec.flac', $languageCode = 'fr-FR', $options = ['sampleRateHertz' => 16000, 'speechContexts' => ['phrases' => ['The Google Cloud Platform', 'Speech API']]])
{
// Create the speech client
$speech = new SpeechClient([
'keyFilePath' => 'C:\Users\Poste3\Downloads\Speech-74da45e82b8e.json',
'languageCode' => $languageCode,
]);
// Make the API call
$results = $speech->recognize(
fopen($audioFile, 'r'),
$options
);
// Print the results
foreach ($results as $result) {
$alternative = $result->alternatives()[0];
printf('Transcript: %s' . PHP_EOL, $alternative['transcript']);
printf('Confidence: %s' . PHP_EOL, $alternative['confidence']);
}
return $this->render('OCPlatformBundle:Advert:speech.html.twig');
}
这是对函数的调用
{{ render(controller('OCPlatformBundle:Advert:transcribe')) }}
【问题讨论】:
标签: php symfony google-speech-api