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
Visit https://github.com/acrcloud/acrcloud_sdk_golang to choose the suitable version according to your needs
# 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
The most convenient way
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
$ go get github.com/acrcloud/acrcloud_sdk_golang/acrcloud
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)
}
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)
}
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)
}
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)
}
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)
}
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 modified 1yr ago