iammordaty / musly-php
PHP 封装 `musly` 命令的包装器
0.5.2
2022-01-21 13:39 UTC
Requires
- php: >=8.0
- symfony/process: >=4.2
Requires (Dev)
- phpstan/phpstan: ^1.4
- phpunit/phpunit: ^9.5
README
musly-php 是一个简单的 PHP 封装,用于 `musly` 命令行工具。
Musly 是一个由 C/C++ 编写的快速、高质量的音频音乐相似性库。
-- Musly 网站
安装
建议使用 Composer 安装 musly-php。
$ composer require iammordaty/musly-php
要求
您可能还对 iammordaty/musly 分支感兴趣,该分支允许您获取相似音轨之间的距离(更多信息请参阅 PR #51)。
基本用法
use Musly\Musly; $musly = new Musly(); $musly->initializeCollection(); $musly->analyze('/path/to/dir/or/track.mp3'); $similarTracks = $musly->getSimilarTracks('/path/to/track.mp3');
高级用法
use Musly\Collection use Musly\Exception\FileNotFoundException use Musly\Exception\FileNotFoundInCollectionException use Musly\Exception\MuslyProcessFailedException use Musly\Musly; $collection = new Collection([ 'pathname' => '/path/to/collection.musly', 'similarityMethod' => Collection::SIMILARITY_METHOD_TIMBRE, 'jukeboxPathname' => '/path/to/collection.jbox', ]); // ... or // $collection = new Collection('/path/to/collection.musly'); // $collection->setSimilarityMethod(Collection::SIMILARITY_METHOD_TIMBRE); // $collection->setJukeboxPathname('/path/to/collection.jbox'); $musly = new Musly([ 'binary' => '/path/to/musly/binary' ]); try { if (!$collection->isInitialized()) { $musly->initializeCollection($collection); } $musly->setCollection($collection); $musly->analyze('/path/to/dir/', 'mp3'); $musly->analyze('/path/to/track.mp3'); $similarTracks = $musly->getSimilarTracks('/path/to/track.mp3', 20); $collectionTracks = $musly->getAllTracks(); } catch (FileNotFoundException | FileNotFoundInCollectionException $e) { // handle exception } catch (MuslyProcessFailedException $e) { // handle exception }
有关更多信息,请参阅 `musly` 命令行工具的帮助。
测试
将 phpunit.xml.dist
文件复制到 phpunit.xml
,并使用 PHPUnit 运行测试
$ ./vendor/bin/phpunit
更多信息
许可证
iammordaty/musly-php 在 MIT 许可证下授权。