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 ?