Skip to content
Advertisement

Laravel 8 (PHP) & Google Cloud Speech API: Streaming calls are not supported while using the REST transport.)

Wassup Guys,

I’ve managed to install the Google Cloud Speech Api and use my .json file as credentials for the speech client.

Now I’m getting the “Streaming calls are not supported while using the REST transport.” error.

Did I miss something? Below is the method of my controller. AudioController.php

<?php

namespace AppHttpControllers;


use IlluminateHttpRequest;

use GoogleCloudSpeechV1RecognitionConfigAudioEncoding;
use GoogleCloudSpeechV1RecognitionConfig;
use GoogleCloudSpeechV1StreamingRecognitionConfig;
use IlluminateSupportFacadesStorage;
use SymfonyComponentHttpFoundationResponse;
use GoogleCloudSpeechV1SpeechClient;


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);
        }
    }
}

Advertisement

Answer

Make sure gRPC for PHP is installed and enabled.

Check your php.ini file for:

extension=grpc.so – Linux.

extension=php_grpc.dll – Windows.

Add the composer dependency:

composer require "grpc/grpc:^1.38"

Install gRPC for PHP

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement