我正在使用Google Speech API,但是它确实很不稳定并且实际上不可用。
我正在尝试API的同步/异步服务,但结果是相同的。
这是我的代码示例,它使用异步服务来转录音频:
putenv('GOOGLE_APPLICATION_CREDENTIALS=E:\PHP\google.json');
# Your Google Cloud Platform project ID
$projectId = 'xxx';
# Instantiates a client
$speech = new SpeechClient([
'projectId' => $projectId,
'languageCode' => 'en-GB',
'requestTimeout' => 30
]);
# The audio file's encoding and sample rate
$options = [
'encoding' => 'LINEAR16',
'model' => 'default',
];
# Detects speech in the audio file
var_dump('beginRecognizeOperation:before');
$operation = $speech->beginRecognizeOperation(fopen($fileName, 'rb'), $options);
var_dump('beginRecognizeOperation:after');
$bIsComplete = $operation->isComplete();
while (!$bIsComplete) {
sleep(1);
$operation->reload();
$bIsComplete = $operation->isComplete();
}
$results = $operation->results()[0];
var_dump($results->topAlternative());
它通常挂在“ beginRecognizeOperation”上,如果我没有在SpeechClient构造函数中设置超时,它将永远挂在那里。
所以第一个问题是超时。我经常(75%)收到此错误,并将超时设置为30秒。
PHP Fatal error: Uncaught Google\Cloud\Core\Exception\ServiceException: cURL error 28: Operation timed out after 30015 milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in \composer\vendor\google\cloud-core\src\RequestWrapper.php:263
Stack trace:
#0 \composer\vendor\google\cloud-core\src\RequestWrapper.php(168): Google\Cloud\Core\RequestWrapper->convertToGoogleException(Object(GuzzleHttp\Exception\ConnectException))
#1 \composer\vendor\google\cloud-core\src\RestTrait.php(95): Google\Cloud\Core\RequestWrapper->send(Object(GuzzleHttp\Psr7\Request), Array)
#2 \composer\vendor\google\cloud-speech\src\Connection\Rest.php(70): Google\Cloud\Speech\Connection\Rest->send('speech', 'longrunningreco...', Array)
#3 \composer\vendor\google\cloud-speech\src\SpeechClient.php(348): Google\Cloud\Speech\Connection\Rest->longRunningRecognize(Array)
#4 \lib\Google\SpeechToTextAsync.php(42): Google\Cloud\Speech\ in \composer\vendor\google\cloud-core\src\RequestWrapper.php on line 263
我有时(10%)遇到的第二个错误是关于SSL的。
Fatal error: Uncaught Google\Cloud\Core\Exception\ServiceException: cURL error 56: OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in composer\vendor\google\cloud-core\src\RequestWrapper.php:263
Stack trace:
#0 composer\vendor\google\cloud-core\src\RequestWrapper.php(168): Google\Cloud\Core\RequestWrapper->convertToGoogleException(Object(GuzzleHttp\Exception\RequestException))
#1 composer\vendor\google\cloud-core\src\RestTrait.php(95): Google\Cloud\Core\RequestWrapper->send(Object(GuzzleHttp\Psr7\Request), Array)
#2 composer\vendor\google\cloud-speech\src\Connection\Rest.php(70): Google\Cloud\Speech\Connection\Rest->send('speech', 'longrunningreco...', Array)
#3 composer\vendor\google\cloud-speech\src\SpeechClient.php(348): Google\Cloud\Speech\Connection\Rest->longRunningRecognize(Array)
#4 lib\Google\SpeechToTextAsync.php(42): Google\Cloud\Speech\SpeechClient->begi in composer\vendor\google\cloud-core\src\RequestWrapper.php on line 263
PHP Fatal error: Uncaught Google\Cloud\Core\Exception\ServiceException: cURL error 56: OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in composer\vendor\google\cloud-core\src\RequestWrapper.php:263
其余15%的尝试是成功的呼叫,并返回了正确的转录文本。因此,这确实验证了服务的设置正确,但工作不可靠。
我的互联网连接稳定,并且没有超出Google API控制台的任何限制。我要转录的音频(WAV)文件的大小约为5mb,长度为1分钟。
在Google API控制台中可以下载一些“ API方法错误。csv错误” CSV,其中可能包含一些有用的信息。但是,谷歌已将其破坏了-当我尝试下载它时,只有一些加载程序开始旋转,但是没有下载任何东西,即使根据图形显示,也存在一些错误。其他CSV报告效果很好。
API有什么问题?