masterfermin02/php-audio-text-summary
最新稳定版本:v1.0.0
Composer 安装命令:
composer require masterfermin02/php-audio-text-summary
包简介
PHP package to transcribe recordings or audio to text and summary using google speech to text and chatGPT
README 文档
README
PHP package speech to text (audio, recordings) and make a summary.
This package is using the OpenAI and Google cloud speech to text
Google Authentication
Please see our Authentication guide for more information on authenticating your client. Once authenticated, you'll be ready to start making requests.
ChatGPT ApiKey
Requirement
Requires PHP 8.1+
Installation
You can install the package via composer:
composer require masterfermin02/php-audio-text-summary
Usage
use Google\Cloud\Speech\V1\RecognitionAudio; use Google\Cloud\Speech\V1\RecognitionConfig; use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding; use DaimonDove\Transcription\Transcriber; $client = OpenAI::client('YOUR_API_KEY'); $googleCredentials = ['credentials' => 'YOUR_GOOGLE_API_CREDENTAILS']; $speechToText = Transcriber::create($client, $googleCredentials); # The name of the audio file to transcribe $gcsURI = 'gs://cloud-samples-data/speech/brooklyn_bridge.raw'; # set string as audio content $audio = (new RecognitionAudio()) ->setUri($gcsURI); # The audio file's encoding, sample rate and language $config = new RecognitionConfig([ 'encoding' => AudioEncoding::LINEAR16, 'sample_rate_hertz' => 16000, 'language_code' => 'en-US' ]); echo $speechToText->recognize($config, $audio) ->summary(); // Get others alternatives for tests $response = $speechToText->getRecognizeText(); # Print most likely transcription foreach ($response->getResults() as $result) { $alternatives = $result->getAlternatives(); $mostLikely = $alternatives[0]; $transcript = $mostLikely->getTranscript(); printf('Summary: %s' . PHP_EOL, $speechToText->summaryText($transcript)); }
You can also use a file resource
use Google\Cloud\Speech\V1\RecognitionConfig\AudioEncoding; use Google\Cloud\Speech\V1\RecognitionConfig; use Google\Cloud\Speech\V1\StreamingRecognitionConfig; use DaimonDove\Transcription\Transcriber; $recognitionConfig = new RecognitionConfig(); $recognitionConfig->setEncoding(AudioEncoding::FLAC); $recognitionConfig->setSampleRateHertz(44100); $recognitionConfig->setLanguageCode('en-US'); $config = new StreamingRecognitionConfig(); $config->setConfig($recognitionConfig); $audioResource = fopen('path/to/audio.flac', 'r'); $client = OpenAI::client('YOUR_API_KEY'); $googleCredentials = ['credentials' => 'YOUR_GOOGLE_API_CREDENTAILS']; $speechToText = Transcriber::create($client, $googleCredentials); echo $speechToText->recognizeAudioStream($config, $audioResource)->summary(); $responses $speechToText->getRecognizeAudioStreamText(); foreach ($responses as $element) { // doSomethingWith($element); }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-03