Skip to content

Latest commit

History

73 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Audio Recognition Java SDK

Overview

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 java SDK support most of audio / video files.

Audio: mp3, wav, m4a, flac, aac, amr, ape, ogg ...
Video: mp4, mkv, wmv, flv, ts, avi ...

Requirements

Follow one of the tutorials to create a project and get your host, access_key and access_secret.

Windows Runtime Library

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)

Note

  1. You must not modify package name "com.acrcloud.utils".
  2. If you run the SDK on Windows, you must install library(vcredist).

Maven

<dependency>
<groupId>com.acrcloud.sdks</groupId>
<artifactId>com.acrcloud.sdks.recognizer</artifactId>
<version>1.0.6</version>
</dependency>

Functions

Introduction all API.

src/com/acrcloud/utils/ACRCloudRecognizer.java

publicStringrecognizeByFile(StringfilePath, intstartSeconds)
/** * * recognize by file path of (Audio/Video file) * Audio: mp3, wav, m4a, flac, aac, amr, ape, ogg ... * Video: mp4, mkv, wmv, flv, ts, avi ... * * @param filePath query file path * @param startSeconds skip (startSeconds) seconds from from the beginning of (filePath) * * @return result * **/publicStringrecognizeByFileBuffer(byte[] fileBuffer, intfileBufferLen, intstartSeconds)
/** * * recognize by buffer of (Audio/Video file) * Audio: mp3, wav, m4a, flac, aac, amr, ape, ogg ... * Video: mp4, mkv, wmv, flv, ts, avi ... * * @param fileBuffer query buffer * @param fileBufferLen the length of fileBufferLen * @param startSeconds skip (startSeconds) seconds from from the beginning of fileBuffer * * @return result * **/publicStringrecognize(byte[] wavAudioBuffer, intwavAudioBufferLen)
/** * * recognize by wav audio buffer(RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz) * * @param wavAudioBuffer query audio buffer * @param wavAudioBufferLen the length of wavAudioBuffer * * @return result * **/

src/com/acrcloud/utils/ACRCloudExtrTool.java

publicstaticbyte[] createFingerprintByFile(StringfileName, intstartTimeSeconds, intaudioLenSeconds, booleanisDB)
//fileName: Path of input file;//startTimeSeconds: Start time of input file, default is 0;//audioLenSeconds: Length of audio data you need. if you create recogize frigerprint, default is 12 seconds, if you create db frigerprint, it is not usefully;//isDB: If it is True, it will create db frigerprint;//@return "ACRCloud Fingerprint". If can not create frigerprint, return null.publicstaticbyte[] createFingerprintByFileBuffer(byte[] dataBuffer, intdataBufferLen, intstartTimeSeconds, intaudioLenSeconds, booleanisDB)
//dataBuffer: data buffer of input file;//dataBufferLen: length of dataBuffer//startTimeSeconds: Start time of input file, default is 0;//audioLenSeconds: Length of audio data you need. if you create recogize frigerprint, default is 12 seconds, if you create db frigerprint, it is not usefully;//isDB: If it is True, it will create db frigerprint;//@return "ACRCloud Fingerprint". If can not create frigerprint, return null.publicstaticbyte[] createFingerprint(byte[] dataBuffer, intdataBufferLen, booleanisDB)
//dataBuffer: audio data buffer(RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz);//isDB: If it is True, it will create db frigerprint;//@return "ACRCloud Fingerprint". If can not create frigerprint, return null.publicstaticbyte[] decodeAudioByFile(StringfileName, intstartTimeSeconds, intaudioLenSeconds) //It will return the audio data(RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz);//fileName: Path of input file;//startTimeSeconds: Start time of input file, default is 0;//audioLenSeconds: Length of audio data you need, if it is 0, will decode all the audio;//@return audio data.publicstaticbyte[] decodeAudioByFileBuffer(byte[] dataBuffer, intdataBufferLen, intstartTimeSeconds, intaudioLenSeconds)
//It will return the audio data(RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz);//dataBuffer: data buffer of input file;//startTimeSeconds: Start time of input file, default is 0;//audioLenSeconds: Length of audio data you need, if it is 0, will decode all the audio;//@return audio data.defversion()
//return the version of this module

Example

run Test:
>>> cd test
Replace "xxxxxxxx" below with your project's access_key and access_secret.
>>> sh run.sh

importjava.io.*;
importjava.util.Map;
importjava.util.HashMap;
importcom.acrcloud.utils.ACRCloudRecognizer;
publicclassTest {
publicstaticvoidmain(String[] args) {
Map<String, Object> config = newHashMap<String, Object>();
// replace "XXXXXXXX" with your project's host, access_key and access_secretconfig.put("host", "XXXXXXXX");
config.put("access_key", "XXXXXXXX");
config.put("access_secret", "XXXXXXXX");
config.put("debug", false);
config.put("timeout", 10); // secondsACRCloudRecognizerre = newACRCloudRecognizer(config);
// It will skip 80 seconds.Stringresult = re.recognizeByFile(args[0], 80);
System.out.println(result);
/** * * recognize by buffer of (Formatter: Audio/Video) * Audio: mp3, wav, m4a, flac, aac, amr, ape, ogg ... * Video: mp4, mkv, wmv, flv, ts, avi ... * * **/Filefile = newFile(args[0]);
byte[] buffer = newbyte[3 * 1024 * 1024];
if (!file.exists()) {
return;
}
FileInputStreamfin = null;
intbufferLen = 0;
try {
fin = newFileInputStream(file);
bufferLen = fin.read(buffer, 0, buffer.length);
} catch (Exceptione) {
e.printStackTrace();
} finally {
try {
if (fin != null) {
fin.close();
}
} catch (IOExceptione) {
e.printStackTrace();
}
}
System.out.println("bufferLen=" + bufferLen);
if (bufferLen <= 0)
return;
// It will skip 80 seconds from the begginning of (buffer).result = re.recognizeByFileBuffer(buffer, bufferLen, 80);
System.out.println(result);
}
}

Eclipse Project

1. create java project:
image
2. add jar library, click right-hand on "commons-codec-1.10.jar" >> Build Path >> Add to Build Path:
image
image
3.add (dll or so) library:
image

About

No description, website, or topics provided.

Resources

Stars

27 stars

Watchers

8 watching

Forks

Releases

Packages

Contributors

Languages