ACRCloud provides services such as Music Recognition, Broadcast Monitoring, Custom Audio Recognition, Copyright Compliance & Data Deduplication, Live Channel Detection, and Offline Recognition etc.
This audio recognition PHP SDK support most of audio / video files.
Audio: mp3, wav, m4a, flac, aac, amr, ape, ogg ...
Video: mp4, mkv, wmv, flv, ts, avi ...
Follow one of the tutorials to create a project and get your host, access_key and access_secret.
- Recognize Music
- Recognize Custom Content
- Broadcast Monitoring for Music
- Broadcast Monitoring for Custom Content
- Detect Live & Timeshift TV Channels
- Recognize Custom Content Offline
- Recognize Live Channels and Custom Content
If you run the SDK on Windows, you must install this library.
X86: download and install Library(windows/vcredist_x86.exe)
x64: download and install Library(windows/vcredist_x64.exe)
- If you run the SDK on Windows, you must install library(vcredist).
Note: If you use nginx/apache, you can add "phpinfo()" in your code, and find extension dir and the path of "php.ini" from the result info
- Find your extension dir, run(this is default extension dir):
$ php -ini | grep "extension_dir"
extension_dir => /usr/lib64/php/modules => /usr/lib64/php/modules
- Put "acrcloud_extr_tool.so" to /usr/lib64/php/modules;(Your extension dir)
- Find your path of php.ini file:
$ php -ini | grep "php.ini"
Loaded Configuration File => /etc/php.ini
If you use this SDK in Web Server, you need to find "php.ini" by "phpinfo()".
4. Modify file "/etc/php.ini"(Your php.ini)
extension=acrcloud_extr_tool.so
Introduction all API.
class ACRCloudRecognizer {
/**
*
* recognize by file path of (Audio/Video file)
* Audio: mp3, wav, m4a, flac, aac, amr, ape, ogg ...
* Video: mp4, mkv, wmv, flv, ts, avi ...
*
* Notice: this function read max 12 seconds from "startSeconds of input file" and only recognize once.
*
*
* @param filePath query file path
* @param startSeconds skip (startSeconds) seconds from from the beginning of (filePath)
*
* @return result metainfos https://docs.acrcloud.com/metadata
*
**/
public function recognizeByFile($filePath, $startSeconds);
/**
*
* recognize by buffer of (Audio/Video file)
* Audio: mp3, wav, m4a, flac, aac, amr, ape, ogg ...
* Video: mp4, mkv, wmv, flv, ts, avi ...
* Notice: this function read max 12 seconds from "startSeconds of input file" and only recognize once.
*
* @param fileBuffer query buffer
* @param startSeconds skip (startSeconds) seconds from from the beginning of fileBuffer
*
* @return result metainfos https://docs.acrcloud.com/metadata
*
**/
public function recognizeByFileBuffer($fileBuffer, $startSeconds);
/**
*
* recognize by wav audio buffer(RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz)
*
* @param wavAudioBuffer query audio buffer
*
* @return result metainfos https://docs.acrcloud.com/metadata
*
**/
public function recognize($wavAudioBuffer);
}
run Test: php test.php test.mp3
<?php namespace ACRCloud;
include_once('acrcloud_recognizer.php');
// Replace "xxxxxxxx" below with your project's host, access_key and access_secret.
$config = array(
'host' => 'XXX',
'access_key' => 'XXX',
'access_secret' => 'XXX'
);
// recognize by file path, and skip 0 seconds from from the beginning of sys.argv[1].
// Notice: this function read max 12 seconds from "startSeconds of input file" and only recognize once.
$re = new ACRCloudRecognizer($config);
print $re->recognizeByFile($argv[1], 0);
// recognize by file_audio_buffer that read from file path, and skip 0 seconds from from the beginning of sys.argv[1].
// Notice: this function read max 12 seconds from "startSeconds of input file" and only recognize once.
$content = file_get_contents($argv[1]);
print $re->recognizeByFileBuffer($content, 0);
// If need scan a audio file, you can refer to this code.
$file_duration_ms = ACRCloudExtrTool::getDurationFromFile($argv[1]);
for ($startSeconds=0; $startSeconds<$file_duration_ms/1000; $startSeconds=$startSeconds+12) {
print $re->recognizeByFile($argv[1], $startSeconds);
}
?>