2

I'm a PHP developer, I would like to use transcribe real time transcriptions, but I haven't found documentation for PHP about this tool, do you have a strength? For audio translation, I found it, but I didn't find real time. Below audio conversion example:

 //Storage::disk('temp')->get('1.mp3');
    // // https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-transcribe-2017-10-26.html
    // https://docs.aws.amazon.com/transcribe/latest/dg/streaming.html
    public function transcribeVoice(Request $request)
    {
        $client = AWS::createClient('transcribeService');
        $path = 'https://audio-job.s3.us-east-2.amazonaws.com/audio.mp3';
        try {
            $result = $client->getTranscriptionJob([
                'TranscriptionJobName' => 'audio-job'
            ]);
            if ($result['TranscriptionJob']['TranscriptionJobStatus'] == 'IN_PROGRESS') {
                return redirect('/')->with('status', 'Progressing now');
            } else if ($result['TranscriptionJob']['TranscriptionJobStatus'] == 'COMPLETED') {
                $file = file_get_contents($result['TranscriptionJob']['Transcript']['TranscriptFileUri']);
                $json = json_decode($file);
                $transcript = $json->results->transcripts[0]->transcript;
                $client->deleteTranscriptionJob([
                    'TranscriptionJobName' => 'audio-job', // REQUIRED
                ]);
                return redirect('/transcribeVoice')->with('result', $transcript);
            }
        } catch (Aws\TranscribeService\Exception\TranscribeServiceException $e) {
            $result = $client->startTranscriptionJob([
                'LanguageCode' => 'pt-BR', // REQUIRED
                'Media' => [ // REQUIRED
                    'MediaFileUri' => $path,
                ],
                'MediaFormat' => 'mp3', // REQUIRED
                'TranscriptionJobName' => 'audio-job', // REQUIRED
            ]);
            return redirect('/transcribeVoice')->with('status', 'Progressing now');
        }
    }
}
// StartStreamTranscription – Starts a bi-directional HTTP/2 stream where audio is streamed to Amazon Transcribe and the transcription results are streamed to your application.
// https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.TranscribeService.TranscribeServiceClient.html

0 Answers0