musly-php is simple PHP wrapper around the musly
commandline tool.
Musly is a fast and high-quality audio music similarity library written in C/C++.
It's recommended that you use Composer to install musly-php.
$ composer require iammordaty/musly-php
- PHP 8.0
- Musly with commandline tool
You may also be interested in iammordaty/musly fork, which allows you to get the distance between similar tracks (see PR #51 for more info).
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
}
See the musly
commandline tool help for more information.
Copy phpunit.xml.dist
file to phpunit.xml
and use PHPUnit to run tests:
$ ./vendor/bin/phpunit
iammordaty/musly-php is licensed under the MIT License.