ACRCloud
Search…
Go
Go SDK installation and usage
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
GitHub - acrcloud/acrcloud_sdk_golang
GitHub

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)

1
# Add environment variables
2
# Replace acrcloud_dlib_path with libacrcloud_extr_tool.so
3
$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/acrcloud_dlib_path/
4
$ export LD_LIBRARY_PATH
Copied!

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
1
# donwload the lib
2
$ 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
3
# Creating dynamic library configuration files
4
$ sudo bash -c "echo /usr/local/lib > /etc/ld.so.conf.d/acrcloud.conf"
5
# Update system configuration
6
$ sudo ldconfig
Copied!

Use go get to get the SDK

1
$ go get github.com/acrcloud/acrcloud_sdk_golang/acrcloud
Copied!

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.
1
package main
2
3
import "github.com/acrcloud/acrcloud_sdk_golang/acrcloud"
4
5
func main() {
6
7
host := "Host"
8
accessKey := "Access Key"
9
accessSecret := "Access Secret"
10
11
configs := map[string]string{
12
"access_key": accessKey,
13
"access_secret": accessSecret,
14
"host": host,
15
"recognize_type": acrcloud.ACR_OPT_REC_AUDIO,
16
}
17
18
var recHandler = acrcloud.NewRecognizer(configs)
19
20
}
21
Copied!

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:
1
package main
2
3
import (
4
"fmt"
5
"github.com/acrcloud/acrcloud_sdk_golang/acrcloud"
6
)
7
8
func main() {
9
filename := "test.mp4"
10
host := "Host"
11
accessKey := "Access Key"
12
accessSecret := "Access Secret"
13
14
configs := map[string]string{
15
"access_key": accessKey,
16
"access_secret": accessSecret,
17
"host": host,
18
"recognize_type": acrcloud.ACR_OPT_REC_AUDIO,
19
}
20
21
recHandler := acrcloud.NewRecognizer(configs)
22
23
userParams := map[string]string{}
24
25
result := recHandler.RecognizeByFile(filename, 0, 10, userParams)
26
fmt.Println(result)
27
}
Copied!

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:
1
package main
2
3
import (
4
"fmt"
5
"github.com/acrcloud/acrcloud_sdk_golang/acrcloud"
6
"io/ioutil"
7
)
8
9
func main() {
10
filename := "test.mp4"
11
buffer, _ := ioutil.ReadFile(filename)
12
13
host := "Host"
14
accessKey := "Access Key"
15
accessSecret := "Access Secret"
16
17
configs := map[string]string{
18
"access_key": accessKey,
19
"access_secret": accessSecret,
20
"host": host,
21
"recognize_type": acrcloud.ACR_OPT_REC_AUDIO,
22
}
23
24
recHandler := acrcloud.NewRecognizer(configs)
25
26
userParams := map[string]string{}
27
28
result := recHandler.RecognizeByFileBuffer(buffer, 0, 10, userParams)
29
fmt.Println(result)
30
31
}
32
Copied!

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:
1
package main
2
3
import (
4
"fmt"
5
"github.com/acrcloud/acrcloud_sdk_golang/acrcloud"
6
"io/ioutil"
7
)
8
9
func main() {
10
filename := "test.mp4.db.lo"
11
buffer, _ := ioutil.ReadFile(filename)
12
13
host := "Host"
14
accessKey := "Access Key"
15
accessSecret := "Access Secret"
16
17
configs := map[string]string{
18
"access_key": accessKey,
19
"access_secret": accessSecret,
20
"host": host,
21
"recognize_type": acrcloud.ACR_OPT_REC_AUDIO,
22
}
23
24
recHandler := acrcloud.NewRecognizer(configs)
25
26
userParams := map[string]string{}
27
28
result := recHandler.RecognizeByFpBuffer(buffer, 0, 10, userParams)
29
fmt.Println(result)
30
31
}
Copied!

GetDurationMsByFile(filePath string)

Get the length of the multimedia file
params
description
filePath
string,Multimedia file path
Sample Code:
1
package main
2
3
import (
4
"fmt"
5
"github.com/acrcloud/acrcloud_sdk_golang/acrcloud"
6
)
7
8
func main() {
9
filename := "test.mp4"
10
host := "Host"
11
accessKey := "Access Key"
12
accessSecret := "Access Secret"
13
14
configs := map[string]string{
15
"access_key": accessKey,
16
"access_secret": accessSecret,
17
"host": host,
18
"recognize_type": acrcloud.ACR_OPT_REC_AUDIO,
19
}
20
21
recHandler := acrcloud.NewRecognizer(configs)
22
result, _ := recHandler.GetDurationMsByFile(filename)
23
fmt.Println(result)
24
}
25
Copied!

GetDurationMsByFpBuffer(fpBufferData []byte)

Get the length of the fingerprint file
参数
描述
fpBufferData
Buffer of the fingerprint file
Sample Code:
1
package main
2
3
import (
4
"fmt"
5
"github.com/acrcloud/acrcloud_sdk_golang/acrcloud"
6
"io/ioutil"
7
)
8
9
func main() {
10
filename := "test.mp4.db.lo"
11
buffer, _ := ioutil.ReadFile(filename)
12
13
host := "Host"
14
accessKey := "Access Key"
15
accessSecret := "Access Secret"
16
17
configs := map[string]string{
18
"access_key": accessKey,
19
"access_secret": accessSecret,
20
"host": host,
21
"recognize_type": acrcloud.ACR_OPT_REC_AUDIO,
22
}
23
24
recHandler := acrcloud.NewRecognizer(configs)
25
26
result, _ := recHandler.GetDurationMsByFpBuffer(buffer)
27
fmt.Println(result)
28
29
}
30
Copied!
Last modified 3mo ago