Go

Go SDK installation and usage

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

Visit https://github.com/acrcloud/acrcloud_sdk_golang to choose the suitable version according to your needs

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)

# 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

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

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)

}

Last updated