# Go

{% hint style="warning" %}
The Go SDK currently only supports Linux and macOS
{% endhint %}

{% hint style="info" %}
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
{% endhint %}

{% embed url="<https://github.com/acrcloud/acrcloud_sdk_golang>" %}

## Obtain SDK <a href="#huo-qu-sdk" id="huo-qu-sdk"></a>

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

### Adding dynamic libraries

#### &#x20;<a href="#id-1-jiang-dong-tai-ku-suo-zai-lu-jing-tian-jia-dao-huan-jing-bian-liang-lin-shi" id="id-1-jiang-dong-tai-ku-suo-zai-lu-jing-tian-jia-dao-huan-jing-bian-liang-lin-shi"></a>

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

```bash
# 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)

{% hint style="warning" %}
The following commands all require root privileges to run
{% endhint %}

```bash
# 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

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

## Initialization

First go to [ACRCloud Developer Platform](https://console.acrcloud.com/) **Console** > **Audio & Video Recognition** to get **Access Key, Access Secret** and **Host.**

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

```go
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) <a href="#recognizebyfile-filepath-string-startseconds-int-lenseconds-int-userparams-map-string-string" id="recognizebyfile-filepath-string-startseconds-int-lenseconds-int-userparams-map-string-string"></a>

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:

```go
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) <a href="#recognizebyfilebuffer-data-byte-startseconds-int-lenseconds-int-userparams-map-string-string" id="recognizebyfilebuffer-data-byte-startseconds-int-lenseconds-int-userparams-map-string-string"></a>

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:

```go
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) <a href="#recognizebyfpbuffer-data-byte-startseconds-int-lenseconds-int-userparams-map-string-string" id="recognizebyfpbuffer-data-byte-startseconds-int-lenseconds-int-userparams-map-string-string"></a>

Identify the location of the fingerprint file that has been read

{% hint style="info" %}
The usage and detail for generating fingerprint files can be found in the TOOLS > Audio File Fingerprinting Tool
{% endhint %}

| 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:

```go
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) <a href="#getdurationmsbyfile-filepath-string" id="getdurationmsbyfile-filepath-string"></a>

Get the length of the multimedia file

| params   | description                 |
| -------- | --------------------------- |
| filePath | string，Multimedia file path |

Sample Code:

```go
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) <a href="#getdurationmsbyfpbuffer-fpbufferdata-byte" id="getdurationmsbyfpbuffer-fpbufferdata-byte"></a>

Get the length of the fingerprint file

| params       | description                    |
| ------------ | ------------------------------ |
| fpBufferData | Buffer of the fingerprint file |

Sample Code:

```go
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)

}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.acrcloud.com/sdk-reference/backend-sdk/go.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
