invis1ble / media-intelligence
一个用于处理和分析媒体内容的库,提供音频、视频和文本分析的工具。
2.0.0
2023-03-12 22:44 UTC
Requires
- php: >=8.2
- guzzlehttp/guzzle: ^7.5@dev
- psr/http-client: ^1.0@dev
- psr/http-factory: ^1.0@dev
- psr/http-message: ^1.0@dev
- psr/log: ^3.0@dev
Requires (Dev)
- monolog/monolog: ^3.0@dev
README
此仓库包含适用于媒体分析和处理的PSR兼容代码。
依赖项
为了使用此包,您需要安装以下工具
安装
要安装此包,您可以使用 Composer
composer require invis1ble/media-intelligence
或只需将其添加到您的 composer.json
文件中的依赖项
{ "require": { "invis1ble/media-intelligence": "^2.0" } }
添加上述行后,运行以下命令安装包
composer install
用法
要使用大多数工具,您需要设置 OpenAI API 密钥
<?php // ./public/index.php declare(strict_types=1); require __DIR__ . '/../vendor/autoload.php'; use Invis1ble\MediaIntelligence\VideoToFacts\Application; // Set here your own OpenAI API Key. // Visit https://platform.openai.com/account/api-keys for more details. $openAiApiKey = ''; $audioTargetDirectoryPath = sys_get_temp_dir(); $application = new Application( apiKey: $openAiApiKey, audioTargetDirectory: new SplFileInfo($audioTargetDirectoryPath), ); $facts = $application->run('https://www.youtube.com/watch?v=JdMw9lQTNnc'); /** @var iterable<string> $facts List of the extracted facts */ foreach ($facts as $fact) { echo "- $fact\n"; }
日志设置
要设置日志记录,您需要为要记录的服务设置一个PSR-3兼容的记录器。建议使用 Monolog 作为实现。
// ... use Monolog\Handler\StreamHandler; use Monolog\Level; use Monolog\Logger; // ... $logger = new Logger( name: 'video_to_facts_logger', handlers: [ // write all staff to the file new StreamHandler(__DIR__ . '/../logs/video_to_facts.log', Level::Debug), // write info and higher to console new StreamHandler(STDOUT, Level::Info), ], ); $application = new Application( apiKey: $openAiApiKey, audioTargetDirectory: new SplFileInfo($audioTargetDirectoryPath), debug: true, ); $application->setLogger($logger); $facts = $application->run('https://www.youtube.com/watch?v=JdMw9lQTNnc'); /** @var iterable<string> $facts List of the extracted facts */
上述代码的输出
翻译
您可以将事实翻译成多种语言,只需通过应用程序将语言名称传递给 FactsExtractor 即可。
$application->run('https://www.youtube.com/watch?v=1sRLDDIRL4U', 'Ukrainian');
已知问题和限制
- 目前,由于OpenAI API的限制,我们被迫将长视频分割成较短的片段,这降低了内容分析的效率和准确性。如果您有任何关于如何解决这个问题的问题,请随时在 Issues 中提出,我将乐意考虑您的想法。
敬请期待!