Appearance
Golang
获取 SDK
提示
Go SDK 当前只支持 Linux 和 macOS
访问 https://github.com/acrcloud/acrcloud_sdk_golang 根据需求选择合适的版本
添加动态库
bash
# 添加环境变量
# 这里的 acrcloud_dlib_path 需要替换成 libacrcloud_extr_tool.so 所在文件夹路径
$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/acrcloud_dlib_path/
$ export LD_LIBRARY_PATH
2. 将动态库添加到系统(永久)
提示
以下命令均需要 root 权限运行
bash
# 下载动态库
$ 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
# 创建动态库配置文件
$ sudo bash -c "echo /usr/local/lib > /etc/ld.so.conf.d/acrcloud.conf"
# 更新系统配置
$ sudo ldconfig
使用 go get 获取 SDK
bash
$ go get github.com/acrcloud/acrcloud_sdk_golang/acrcloud
初始化
首先进入 ACRCloud 开发者平台 控制台 > 音频/视频识别 来获取 Access Key, Access Secret 以及 Host。 然后将获取到的配置信息导入 ACRCloudRecognizer 并初始化。
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)
}
方法
RecognizeByFile(filePath string, startSeconds int, lenSeconds int, userParams map[string]string)
识别多媒体文件指定位置
参数 | 描述 |
---|---|
filePath | string,多媒体文件路径 |
startSeconds | int,识别开始位置(单位:秒) |
lenSeconds | int,识别长度(单位:秒,默认为 10,最大不超过 12) |
userParams | map[string]string,搜索参数(仅哼唱搜索有用) |
示例代码:
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)
识别已经读取的多媒体文件指定位置
参数 | 描述 |
---|---|
data | []byte,读取的多媒体文件的 buffer |
startSeconds | int,识别开始位置(单位:秒) |
lenSeconds | int,识别长度(单位:秒,默认为 10,最大不超过 12) |
userParams | map[string]string,搜索参数(仅哼唱搜索有用) |
示例代码:
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)
识别已经读取的指纹文件指定位置
生成指纹文件的方法和详情见 通用工具 > 提指纹工具 部分
参数 | 描述 |
---|---|
data | []byte,读取的指纹文件的buffer |
startSeconds | int,识别开始位置(单位:秒) |
lenSeconds | int,识别长度(单位:秒,默认为 10,最大不超过 12) |
userParams | map[string]string,搜索参数(仅哼唱搜索有用) |
示例代码:
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)
获取多媒体文件的总时长
参数 | 描述 |
---|---|
filePath | string,多媒体文件路径 |
示例代码:
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)
获取指纹文件的总时长
参数 | 描述 |
---|---|
fpBufferData | 读取的指纹文件的buffer |
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)
}
SDK 合规详情:
SDK名称:ACRCloud 音频识别 SDK
开发者:高第网络技术(北京)有限公司
SDK 合规说明与指引: 链接
SDK 隐私政策: 链接