Actualmente estoy escribiendo una aplicación para transcribir archivos de audio cargados o transmitir URL usando Google Cloud Speech to Text Api.
Creé un proyecto de vela de Laravel e instalé el paquete oficial de php de Google Cloud Speech ( https://github.com/googleapis/google-cloud-php-speech ).
Seguí las instrucciones y escribí esto dentro de mi 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); } } }No sé por qué, pero recibo el siguiente error, aunque seguí la documentación oficial e instalé todo correctamente: "Variable no definida $speechClient"
Mi complemento IDE Inteliphase marca los paquetes importados en rojo y dice: "Tipo indefinido 'Google\Cloud\Speech\V1...'.intelephense(1009)"
Me he perdido algo ?