1. Go to this page and download the library: Download kiwilan/php-audio library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kiwilan / php-audio example snippets
use Kiwilan\Audio\Audio;
$audio = Audio::read('path/to/audio.mp3');
$audio->getTitle(); // `?string` to get title
$audio->getArtist(); // `?string` to get artist
$audio->getAlbum(); // `?string` to get album
$audio->getGenre(); // `?string` to get genre
$audio->getYear(); // `?int` to get year
$audio->getTrackNumber(); // `?string` to get track number
$audio->getComment(); // `?string` to get comment
$audio->getAlbumArtist(); // `?string` to get album artist
$audio->getComposer(); // `?string` to get composer
$audio->getDiscNumber(); // `?string` to get disc number
$audio->isCompilation(); // `bool` to know if is compilation
$audio->getCreationDate(); // `?string` to get creation date
$audio->getCopyright(); // `?string` to get copyright
$audio->getEncoding(); // `?string` to get encoding
$audio->getDescription(); // `?string` to get description
$audio->getSynopsis(); // `?string` to get synopsis
$audio->getLanguage(); // `?string` to get language
$audio->getLyrics(); // `?string`
$audio->getDuration(); // `?float` to get duration in seconds
$audio->getDurationHuman(); // `?string` to get duration in human readable format
use Kiwilan\Audio\Audio;
$audio = Audio::read('path/to/audio.mp3');
$raw_all = $audio->getRawAll(); // `array` with all tags
$raw = $audio->getRaw(); // `array` with main tag
$title = $audio->getRawKey('title'); // `?string` to get title same as `$audio->getTitle()`
$format = $audio->getRaw('id3v2'); // `?array` with all tags with format `id3v2`
$title = $audio->getRawKey('title', 'id3v2'); // `?string` to get title with format `id3v2`
use Kiwilan\Audio\Audio;
$audio = Audio::read('path/to/audio.mp3');
$audio->getPath(); // `string` to get path
$audio->getExtension(); // `string` to get extension
$audio->hasCover(); // `bool` to know if has cover
$audio->isValid(); // `bool` to know if file is valid audio file
$audio->isWritable(); // `bool` to know if file is writable
$audio->getFormat(); // `AudioFormatEnum` to get format (mp3, m4a, ...)
$audio->getType(); // `?AudioTypeEnum` ID3 type (id3, riff, asf, quicktime, matroska, ape, vorbiscomment)
use Kiwilan\Audio\Audio;
$audio = Audio::read('path/to/audio.mp3');
$audio->toArray(); // `array` with all metadata
use Kiwilan\Audio\Audio;
$audio = Audio::read('path/to/audio.mp3');
$audio->getId3Reader(); // `?Id3Reader` reader based on `getID3`
$audio->getMetadata(); // `?AudioMetadata` with audio metadata
$audio->getCover(); // `?AudioCover` with cover metadata
use Kiwilan\Audio\Audio;
$audio = Audio::read('path/to/audio.mp3');
$audio->getTitle(); // `Title`
$tag = $audio->write()
->title('New Title')
->artist('New Artist')
->album('New Album')
->genre('New Genre')
->year('2022')
->trackNumber('2/10')
->albumArtist('New Album Artist')
->comment('New Comment')
->composer('New Composer')
->creationDate('2021-01-01')
->description('New Description')
->synopsis('New Synopsis')
->discNumber('2/2')
->encodingBy('New Encoding By')
->encoding('New Encoding')
->isCompilation()
->lyrics('New Lyrics')
->cover('path/to/cover.jpg') // you can use file content `file_get_contents('path/to/cover.jpg')`
->save();
$audio = Audio::read('path/to/audio.mp3');
$audio->getTitle(); // `New Title`
$audio->getCreationDate(); // `null` because `creationDate` is not supported by `MP3`
use Kiwilan\Audio\Audio;
$audio = Audio::read('path/to/audio.mp3');
$audio->getAlbumArtist(); // `Band`
$tag = $audio->write()
->tag('composer', 'New Composer')
->tag('genre', 'New Genre') // can be chained
->tags([
'title' => 'New Title',
'band' => 'New Band', // `band` is used by `id3v2` to set album artist, method is `albumArtist` but `albumArtist` key will throw an exception with `id3v2`
])
->tagFormats(['id3v1', 'id3v2.4']) // optional
->save();
$audio = Audio::read('path/to/audio.mp3');
$audio->getAlbumArtist(); // `New Band`
use Kiwilan\Audio\Audio;
$audio = Audio::read('path/to/audio.mp3');
$audio->getAlbumArtist(); // `Band`
$tag = $audio->write()
->title('New Title')
->albumArtist('New Band') // `albumArtist` will set `band` for `id3v2`, exception safe
->save();
$audio = Audio::read('path/to/audio.mp3');
$audio->getAlbumArtist(); // `New Band`
use Kiwilan\Audio\Audio;
$audio = Audio::read('path/to/audio.mp3');
$tag = $audio->write()
->tags([
'title' => 'New Title',
'title2' => 'New title', // not supported by `id3v2`, will throw an exception
])
->skipErrors() // will prevent exception
->save();
use Kiwilan\Audio\Audio;
$audio = Audio::read('path/to/audio.mp3');
$raw_all = $audio->getRawAll(); // all formats
$raw = $audio->getRaw(); // main format