GithubHelp home page GithubHelp logo

acrclouduniversalsdk's Introduction

ACRCloud Android 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.

Requirements

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

Identify Music or TV

This demo shows how to identify music ( songs ) or detect live TV channels by recorded sound with ACRCloud SDK. Contact us if you have any questions or special requirements about the SDK: [email protected]

Preparation

  • The newest ACRCloud SDK which contains both ObjectC and Swift demo projects.
  • If you want to recognize music, you need an Audio Recognition project. ( See How to Recognize Music )
  • If you want to detect tv channels, you need a Live Channel Detection project. ( See How to Detect Live TV Channels )
  • Save the information of “host”, “access_key”, “access_secret” of your project.
  • Make sure you have Xcode installed.

Directory Description:

  • ACRCloudUniversalSDKDemo demo project

  • libs all librarys of sdk (1) acrcloud-universal-sdk-(version).jar: java library (2) libACRCloudUniversalEngine.so: JNI library

  • docs: https://docs.acrcloud.com/

  • libs-so-tinyalsa If you can not use tinyalsa of libs, you can try this share library.

  • libs-c C/C++ library.

  • If you want to use Offline Version, please use this SDK[offline_version].

Test the demo

[ACRCloudUniversalSDKDemo] is an Android Studio Project, you can add your "host", "access_key" and "access_secret" to recognize music or other contents.

How to use the SDK

  • demo code
public class MainActivity implements IACRCloudListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.mConfig = new ACRCloudConfig();
        this.mConfig.acrcloudListener = this;
        this.mConfig.context = this;
        // Please create project in "http://console.acrcloud.cn/service/avr".
        this.mConfig.host = "XXXXXX";
        this.mConfig.accessKey = "XXXXXX";
        this.mConfig.accessSecret = "XXXXXX";
        
        // If you do not need volume callback, you set it false.
        this.mConfig.recorderConfig.isVolumeCallback = true;

        // By default, pre-recording is enabled and 3s audio is retained. 
        // If you don't need pre-recording, you can set reservedRecordBufferMS = 0
        this.mConfig.recorderConfig.reservedRecordBufferMS = 3000;

        this.mClient = new ACRCloudClient();
        this.initState = this.mClient.initWithConfig(this.mConfig);
    }

    public void start() {
        if (!this.initState) {
            Toast.makeText(this, "init error", Toast.LENGTH_SHORT).show();
            return;
        }

        if (!mProcessing) {
            mProcessing = true;
            mVolume.setText("");
            mResult.setText("");

            // startRecognize: turn on the recording and identify it.
            if (this.mClient == null || !this.mClient.startRecognize()) {
                mProcessing = false;
                mResult.setText("start error!");
            }
            startTime = System.currentTimeMillis();
        }
    }

    public void cancel() {
        if (mProcessing && this.mClient != null) {
            // cancel: cancel the current identify session.
            this.mClient.cancel();
        }

        this.reset();
    }

    @Override
    public void onVolumeChanged(double volume) {
        long time = (System.currentTimeMillis() - startTime) / 1000;
        mVolume.setText(getResources().getString(R.string.volume) + volume + "\n\nTime: " + time + " s");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        Log.e("MainActivity", "release");
        if (this.mClient != null) {
            this.mClient.release();
            this.initState = false;
            this.mClient = null;
        }
    }

    // result callback
    @Override
    public void onResult(ACRCloudResult results) {
        String result = results.getResult();

        String tres = "\n";

        try {
            JSONObject j = new JSONObject(result);
            JSONObject j1 = j.getJSONObject("status");
            int j2 = j1.getInt("code");
            if(j2 == 0){
                JSONObject metadata = j.getJSONObject("metadata");
                //
                if (metadata.has("music")) {
                    JSONArray musics = metadata.getJSONArray("music");
                    for(int i=0; i<musics.length(); i++) {
                        JSONObject tt = (JSONObject) musics.get(i);
                        String title = tt.getString("title");
                        JSONArray artistt = tt.getJSONArray("artists");
                        JSONObject art = (JSONObject) artistt.get(0);
                        String artist = art.getString("name");
                        tres = tres + (i+1) + ".  Title: " + title + "    Artist: " + artist + "\n";
                    }
                }

                tres = tres + "\n\n" + result;
            }else{
                tres = result;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

Low-Level Function

File/PCM/Fingerprint Recognition

if you recognize audio data or get the audio fingerprint, the audio format should be RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16-bit, you also can use the resample function to convert the audio data to what we need.

public ACRCloudClient() {
    /*
        create audio fingerprint from audio buffer.
        
        buffer: audio buffer (format: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16-bit)
        bufferLen: the lenght of buffer
        sampleRate: sample rate of buffer
        nChannels: channel number of buffer
    */
    public static byte[] createClientFingerprint(byte[] buffer, int bufferLen, int sampleRate, int nChannels);

    /*
        create humming fingerprint from audio buffer.
        
        buffer: audio buffer (format: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16-bit)
        bufferLen: the lenght of buffer
        sampleRate: sample rate of buffer
        nChannels: channel number of buffer
    */
    public static byte[] createHummingClientFingerprint(byte[] buffer, int bufferLen, int sampleRate, int nChannels)

    /*
        recognize audio buffer and return the final result.
        
        buffer: audio buffer (format: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16-bit)
        bufferLen: the lenght of buffer
        sampleRate: sample rate of buffer
        nChannels: channel number of buffer
    */
    public String recognize(byte[] buffer, int bufferLen, int sampleRate, int nChannels);

    /*
        recognize fingerprint buffer and return the final result.
        
        buffer: acrcloud fingerprint buffer
        bufferLen: the lenght of buffer
        recType: AUDIO (audio fingerprint), HUMMING (humming fingerprint)
        userParams: Some user-defined parameters.
    */
    public String recognizeFingerprint(byte[] buffer, int bufferLen, ACRCloudConfig.RecognizerType recType, Map<String, String> userParams)
}

acrclouduniversalsdk's People

Contributors

qiuxuewen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

acrclouduniversalsdk's Issues

Lyrics is not getting from the response JSON

While checking the response JSON, we are not getting the Lyrics from it. Only lyrics copyrights details are available.
Also not getting the lyricfind metadata from it. Currently, using the Trial version of ACRCloud whether the details of the lyrics will only available on the Licensed/priced version?

Please check the current JSON ,

{
"status": {
"msg": "Success",
"code": 0,
"version": "1.0"
},
"metadata": {
"music": [
{
"external_ids": {
"isrc": "USJI10800113",
"upc": "886973053621"
},
"external_metadata": {
"deezer": {
"album": {
"name": "Forever"
},
"artists": [
{
"name": "Chris Brown"
}
],
"track": {
"name": "Forever",
"id": "638650"
}
}
},
"title": "Forever",
"album": {
"name": "Forever"
},
"artists": [
{
"name": "Chris Brown"
}
],
"contributors": {
"lyricists": [
"Andre Darrell Merritt",
"Brian Kennedy Seals",
"Jamal Fincher Jones",
"Robert L. Allen",
"Christopher Maurice Brown"
],
"composers": [
"Brian Kennedy",
"Chris Brown",
"Polow da Don",
"Robert Allen",
"Andre Merritt"
]
},
"label": "Jive",
"duration_ms": 278573,
"score": 100,
"release_date": "2008-05-12",
"play_offset_ms": 21640,
"acrid": "b3530488d4ba80ff47ec0990db4b77c4",
"lyrics": {
"copyrights": [
"Sony/ATV Music Publishing LLC",
"Universal Music Publishing Group",
"BMG Rights Management",
"Kobalt Music Publishing Ltd."
]
},
"genres": [
{
"name": "R&B/Soul/Funk"
}
],
"result_from": 3
}
],
"timestamp_utc": "2021-05-21 07:23:50"
},
"cost_time": 0.2279999256134,
"result_type": 0
}

@qiuxuewen FYI

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.