ACRCloud
Visit WebsiteConsole
  • Introduction
  • Get Started
  • Console Tutorials
    • 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
    • Find Potential Detections in Unknown Content Filter
  • SDK REFERENCE
    • Mobile SDK
      • iOS
      • Android
      • Unity
    • Backend SDK
      • Python
      • PHP
      • Go
      • Java
      • C/C++
      • C#
    • Error Codes
  • API Reference
    • Identification API
    • Console API
      • Access Token
      • Buckets
        • Audio Files
        • Live Channels
        • Dedup Files
      • Base Projects
      • OfflineDBs
      • BM Projects
        • Custom Streams Projects
          • Streams
          • Streams Results
          • Streams State
          • Recordings
          • Analytics
          • User Reports
        • Broadcast Database Projects
          • Channels
          • Channels Results
          • Channels State
          • Recordings
          • Analytics
          • User Reports
      • File Scanning
        • FsFiles
      • UCF Projects
        • BM Streams
        • UCF Results
    • Metadata API
  • Tools
    • Audio File Fingerprinting Tool
    • Local Monitoring Tool
    • Live Channel Fingerprinting Tool
    • File Scan Tool
  • Metadata
    • Music
    • Music (Broadcast Monitoring with Broadcast Database)
    • Custom Files
    • Live Channels
    • Humming
  • FAQ
    • Definition of Terms
  • Service Usage
Powered by GitBook
On this page
  • Obtain SDK
  • Adding dynamic libraries
  • Use go get to get the SDK
  • Initialization
  • Method
  • RecognizeByFile(filePath string, startSeconds int, lenSeconds int, userParams map[string]string)
  • RecognizeByFileBuffer(data []byte, startSeconds int, lenSeconds int, userParams map[string]string)
  • RecognizeByFpBuffer(data []byte, startSeconds int, lenSeconds int, userParams map[string]string)
  • GetDurationMsByFile(filePath string)
  • GetDurationMsByFpBuffer(fpBufferData []byte)
  1. SDK REFERENCE
  2. Backend SDK

Go

Go SDK installation and usage

Last updated 2 years ago

The Go SDK currently only supports Linux and macOS

The SDK only offers to identify the content of a specified section of the file, identifying all the content of the entire file requires traversing the entire file

Obtain SDK

Adding dynamic libraries

1. Add the path where the dynamic library is located to the environment variable (temporary)

# Add environment variables 
# Replace acrcloud_dlib_path with libacrcloud_extr_tool.so
$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/acrcloud_dlib_path/
$ export LD_LIBRARY_PATH

2. Place the dynamic library in the same directory as your generated go binary program (temporary)

The most convenient way

3. Adding dynamic libraries to the system (permanently)

The following commands all require root privileges to run

# donwload the lib
$ sudo curl -fsSL https://raw.githubusercontent.com/acrcloud/acrcloud_sdk_golang/master/linux/x86-64/acrcloud/libacrcloud_extr_tool.so -o /usr/local/lib/libacrcloud_extr_tool.so
# Creating dynamic library configuration files
$ sudo bash -c "echo /usr/local/lib > /etc/ld.so.conf.d/acrcloud.conf"
# Update system configuration
$ sudo ldconfig

Use go get to get the SDK

$ go get github.com/acrcloud/acrcloud_sdk_golang/acrcloud

Initialization

The obtained configuration information is then imported into ACRCloudRecognizer and initialized.

package main

import "github.com/acrcloud/acrcloud_sdk_golang/acrcloud"

func main() {

	host := "Host"
	accessKey := "Access Key"
	accessSecret := "Access Secret"

	configs := map[string]string{
		"access_key":     accessKey,
		"access_secret":  accessSecret,
		"host":           host,
		"recognize_type": acrcloud.ACR_OPT_REC_AUDIO,
	}
	
	var recHandler = acrcloud.NewRecognizer(configs)
	
}

Method

RecognizeByFile(filePath string, startSeconds int, lenSeconds int, userParams map[string]string)

Identify the specified location of multimedia files

params

description

filePath

string,Multimedia file path

startSeconds

int,Recognition start position (unit: second)

lenSeconds

int,Identification length (in seconds, default is 10, maximum is 12)

userParams

map[string]string,Search parameters (only humming search is useful)

Sample code:

package main

import (
	"fmt"
	"github.com/acrcloud/acrcloud_sdk_golang/acrcloud"
)

func main() {
	filename := "test.mp4"
	host := "Host"
	accessKey := "Access Key"
	accessSecret := "Access Secret"

	configs := map[string]string{
		"access_key":     accessKey,
		"access_secret":  accessSecret,
		"host":           host,
		"recognize_type": acrcloud.ACR_OPT_REC_AUDIO,
	}

	recHandler := acrcloud.NewRecognizer(configs)

	userParams := map[string]string{}

	result := recHandler.RecognizeByFile(filename, 0, 10, userParams)
	fmt.Println(result)
}

RecognizeByFileBuffer(data []byte, startSeconds int, lenSeconds int, userParams map[string]string)

Identify the specified location of the read multimedia file

params

description

data

[]byte,Buffer of the multimedia file to be read

startSeconds

int,Recognition start position (unit: second)

lenSeconds

int,Identification length (in seconds, default is 10, maximum is 12)

userParams

map[string]string,Search parameters (only humming search is useful)

Sample code:

package main

import (
	"fmt"
	"github.com/acrcloud/acrcloud_sdk_golang/acrcloud"
	"io/ioutil"
)

func main() {
	filename := "test.mp4"
	buffer, _ := ioutil.ReadFile(filename)

	host := "Host"
	accessKey := "Access Key"
	accessSecret := "Access Secret"

	configs := map[string]string{
		"access_key":     accessKey,
		"access_secret":  accessSecret,
		"host":           host,
		"recognize_type": acrcloud.ACR_OPT_REC_AUDIO,
	}

	recHandler := acrcloud.NewRecognizer(configs)

	userParams := map[string]string{}

	result := recHandler.RecognizeByFileBuffer(buffer, 0, 10, userParams)
	fmt.Println(result)

}

RecognizeByFpBuffer(data []byte, startSeconds int, lenSeconds int, userParams map[string]string)

Identify the location of the fingerprint file that has been read

The usage and detail for generating fingerprint files can be found in the TOOLS > Audio File Fingerprinting Tool

params

description

data

[]byte,Buffer of the fingerprint file

startSeconds

int,Recognition start position (unit: second)

lenSeconds

int,Identification length (in seconds, default is 10, maximum is 12)

userParams

map[string]string,Search parameters (only humming search is useful)

Sample Code:

package main

import (
	"fmt"
	"github.com/acrcloud/acrcloud_sdk_golang/acrcloud"
	"io/ioutil"
)

func main() {
	filename := "test.mp4.db.lo"
	buffer, _ := ioutil.ReadFile(filename)

	host := "Host"
	accessKey := "Access Key"
	accessSecret := "Access Secret"

	configs := map[string]string{
		"access_key":     accessKey,
		"access_secret":  accessSecret,
		"host":           host,
		"recognize_type": acrcloud.ACR_OPT_REC_AUDIO,
	}

	recHandler := acrcloud.NewRecognizer(configs)

	userParams := map[string]string{}

	result := recHandler.RecognizeByFpBuffer(buffer, 0, 10, userParams)
	fmt.Println(result)

}

GetDurationMsByFile(filePath string)

Get the length of the multimedia file

params

description

filePath

string,Multimedia file path

Sample Code:

package main

import (
	"fmt"
	"github.com/acrcloud/acrcloud_sdk_golang/acrcloud"
)

func main() {
	filename := "test.mp4"
	host := "Host"
	accessKey := "Access Key"
	accessSecret := "Access Secret"

	configs := map[string]string{
		"access_key":     accessKey,
		"access_secret":  accessSecret,
		"host":           host,
		"recognize_type": acrcloud.ACR_OPT_REC_AUDIO,
	}

	recHandler := acrcloud.NewRecognizer(configs)
	result, _ := recHandler.GetDurationMsByFile(filename)
	fmt.Println(result)
}

GetDurationMsByFpBuffer(fpBufferData []byte)

Get the length of the fingerprint file

params

description

fpBufferData

Buffer of the fingerprint file

Sample Code:

package main

import (
	"fmt"
	"github.com/acrcloud/acrcloud_sdk_golang/acrcloud"
	"io/ioutil"
)

func main() {
	filename := "test.mp4.db.lo"
	buffer, _ := ioutil.ReadFile(filename)

	host := "Host"
	accessKey := "Access Key"
	accessSecret := "Access Secret"

	configs := map[string]string{
		"access_key":     accessKey,
		"access_secret":  accessSecret,
		"host":           host,
		"recognize_type": acrcloud.ACR_OPT_REC_AUDIO,
	}

	recHandler := acrcloud.NewRecognizer(configs)

	result, _ := recHandler.GetDurationMsByFpBuffer(buffer)
	fmt.Println(result)

}

Visit to choose the suitable version according to your needs

First go to Console > Audio & Video Recognition to get Access Key, Access Secret and Host.

https://github.com/acrcloud/acrcloud_sdk_golang
ACRCloud Developer Platform
LogoGitHub - acrcloud/acrcloud_sdk_golangGitHub