【发布时间】:2018-09-26 19:02:49
【问题描述】:
我对这一切都不熟悉,所以请保持温和。我知道基本的 php 并在我的计算机上安装了 WAMP。我所需要的只是一种转录音频文件的简单方法。我安装了 google cloud shell sdk,并使用它来让 composer 安装所需的文件(复制并粘贴来自 google 教程的命令),并将其放入供应商文件夹中。
然后我修改了谷歌放在 github 上的 php 代码,我将在下面粘贴。但是,当我尝试运行 php 文件时,我收到以下错误消息。我究竟做错了什么? :(
<?php
# [START speech_quickstart]
# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';
# Imports the Google Cloud client library
use Google\Cloud\Speech\SpeechClient;
# Your Google Cloud Platform project ID
$projectId = 'xxxx';
# Instantiates a client
$speech = new SpeechClient([
'projectId' => $projectId,
'languageCode' => 'en-US',
]);
# The name of the audio file to transcribe
$fileName = __DIR__ . '/audio/transcribe.mp3';
# The audio file's encoding and sample rate
$options = [
'encoding' => 'LINEAR16',
'sampleRateHertz' => 16000,
'languageCode' => 'en-US',
'enableWordTimeOffsets' => false,
'enableAutomaticPunctuation' => true,
'model' => 'video',
];
# Detects speech in the audio file
$results = $speech->recognize(fopen($fileName, 'r'), $options);
foreach ($results as $result) {
echo 'Transcription: ' . $result->alternatives()[0]['transcript'] . PHP_EOL;
}
# [END speech_quickstart]
return $results;
【问题讨论】:
-
请在您的问题文本中包含minimal reproducible example 和错误消息。
-
这是最小的,因为所有这些都是获取错误消息所必需的。但是,我不知道如何复制它,因为我假设问题出在设置中。
标签: php google-cloud-platform google-speech-api