【问题标题】:Laravel 8 (PHP) & Google Cloud Speech API: Streaming calls are not supported while using the REST transport.)Laravel 8 (PHP) 和 Google Cloud Speech API:使用 REST 传输时不支持流式调用。)
【发布时间】:2021-12-12 03:29:59
【问题描述】:

Wassup 伙计们,

我已成功安装 Google Cloud Speech Api 并将我的 .json 文件用作语音客户端的凭据。

现在我收到“使用 REST 传输时不支持流式调用”。 错误。

我错过了什么吗?下面是我的控制器的方法。 音频控制器.php

<?php

namespace App\Http\Controllers;


use Illuminate\Http\Request;

use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding;
use Google\Cloud\Speech\V1\RecognitionConfig;
use Google\Cloud\Speech\V1\StreamingRecognitionConfig;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\Response;
use Google\Cloud\Speech\V1\SpeechClient;


class AudioController extends Controller
{
    public function getData(Request $request)
    {
        //$url = Storage::download('public/track.mp3');
        $url = asset('storage/test.flac');

        //$file = Storage::disk('public')->get('track.mp3');
        //$download = new Response($file, 200);


        // dd($request->all(), $url);
        return view('welcome')->with('downloadLink', $url);
    }

    public function transcribedText(Request $request)
    {

        $recognitionConfig = new RecognitionConfig();
        $recognitionConfig->setEncoding(AudioEncoding::FLAC);
        $recognitionConfig->setSampleRateHertz(44100);
        $recognitionConfig->setLanguageCode('en-US');
        $config = new StreamingRecognitionConfig();
        $config->setConfig($recognitionConfig);
        $auth = Storage::disk('public')->get('auth.json');
        $test = Storage::path('public/auth.json');
        //dd(file_get_contents($test, true));
        //dd(json_decode($auth));
        //putenv('GOOGLE_APPLICATION_CREDENTIALS='.$auth);
        $speechClient = new SpeechClient([
            'credentials' => Storage::path('public/auth.json'),
        ]);
        $file = Storage::disk('public')->get('test.flac');


        // $audioResource = fopen('path/to/audio.flac', 'r');

        $responses = $speechClient->recognizeAudioStream($config, $file);

        foreach ($responses as $element) {
            dd($element);
        }
    }
}

【问题讨论】:

    标签: php laravel google-cloud-platform speech-to-text


    【解决方案1】:

    确保已安装并启用 gRPC for PHP。

    检查你的 php.ini 文件:

    extension=grpc.so - Linux。

    extension=php_grpc.dll - Windows。

    添加作曲家依赖:

    composer require "grpc/grpc:^1.38"
    

    Install gRPC for PHP

    【讨论】:

    • 我通过 Laravel Sail 在 docker 容器中使用 Laravel。我是否必须在 shell 中安装 gRPC 包,或者这到底是什么方法?
    • @LaFllamme php.ini 和 composer 的步骤是一样的。我不使用 Sail,所以我不确定您如何为该服务复制/安装 php.ini。由于 Sail 基于 Docker,我假设您将设置您的容器并在本地进行测试/验证。然后将容器(或容器 Dockerfile)部署到 Sail。这篇文章可能会有所帮助:hackernoon.com/what-is-wrong-with-laravel-sail-78s314m
    【解决方案2】:

    对于遇到相同问题的任何人:

    Laravel Sail 使用 Vendor/Sail 文件夹下的常规 Dockerfile 以及同一目录中的 php.ini,在构建后被复制。

    只需为 phar 添加这个: && apt-get install autoconf zlib1g-dev php-pear \

    运行 curl -O https://pear.php.net/go-pear.phar 运行 php go-pear.phar 运行 pecl install grpc -q

    还有这个到 php.ini extension=grpc.so

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-26
      • 2017-11-01
      • 2018-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多