Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

607
Visualizações
Laravel 8 & PHP: Use Google Cloud Speech to Text API

I am currently writing an application to transcript uploaded audio files or stream urls using google cloud speech to text api.

I've created a Laravel sail project and installed the official google cloud speech php package (https://github.com/googleapis/google-cloud-php-speech).

I followed the instructions and wrote this inside my AudioController.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;

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);
        $file = Storage::disk('public')->get('test.flac');
        // dd($file);
        // $audioResource = fopen($file, 'r');

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

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

I don't know why, but I get following error, although I've followed the offical documentation and installed everything properly: "Undefined variable $speechClient"

My IDE Plugin Inteliphase marks the imported packages red and states: "Undefined type 'Google\Cloud\Speech\V1...'.intelephense(1009)"

Did I miss something ?

error code controller

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda