Skip to content

Commit

Permalink
Merge pull request #8 from chenqinghe/develop
Browse files Browse the repository at this point in the history
release v0.2
  • Loading branch information
chenqinghe authored Jan 15, 2018
2 parents 0da7b24 + fca021e commit 77b25fa
Show file tree
Hide file tree
Showing 23 changed files with 712 additions and 420 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
.glide/
vendor/
glide.lock
.idea/
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ before_install:
install:
- glide install
script:
- ls
- go build ./voice
- go build ./ocr
- go test ./...
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Baidu-ai-go-sdk ![travis](https://travis-ci.org/chenqinghe/baidu-ai-go-sdk.svg?branch=master)
# Baidu-ai-go-sdk   ![travis](https://travis-ci.org/chenqinghe/baidu-ai-go-sdk.svg?branch=develop)
基于百度REST API封装的go语言sdk,提供简易友好的接口,让开发变得简单。

# Todo list
## 百度语音
- [x] 语音合成
- [x] 语音识别

## 视觉技术

### 文字识别
### 视觉技术

#### 文字识别
- [x] 通用文字识别
- [x] 通用文字识别(含位置信息版)
- [x] 通用文字识别(含生僻字版)
Expand All @@ -19,33 +20,34 @@
- [x] 行驶证识别
- [ ] 表格文字识别

### 人脸识别

#### 人脸识别
- [ ] 人脸检测
- [ ] 人脸对比
- [ ] 人脸查找
- [ ] 人脸库管理
- [ ] 公安验证

### 图像审核
#### 图像审核
- [ ] 图像审核
- [ ] GIF色情识别
- [ ] 图像审核组合服务接口
- [ ] 用户头像审核

### 图像识别
#### 图像识别
- [ ] 通用图像分析
- [ ] 细粒度图像识别
- [ ] 定制化图像识别

### 图像搜索
#### 图像搜索
- [ ] 相同图检索
- [ ] 相似图检索
- [ ] 商品检索


## 自然语言
### 自然语言

### 语言处理基础技术
#### 语言处理基础技术
- [ ] 词法分析
- [ ] 依存句法分析
- [ ] 词向量标识
Expand All @@ -58,10 +60,10 @@
- [ ] 词性标注


### 理解与交互技术UNIT
#### 理解与交互技术UNIT
- [ ] UNIT对话接口

### 文本审核
#### 文本审核
- [ ] 通用类文本反作弊


Expand Down
26 changes: 14 additions & 12 deletions internal/client.go → client.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package internal
package gosdk

import (
"errors"

"github.com/imroc/req"
)

const VOICE_AUTH_URL string = "https://openapi.baidu.com/oauth/2.0/token"
const VOICE_AUTH_URL = "https://openapi.baidu.com/oauth/2.0/token"

//Authorizer 用于设置access_token
//可以通过RESTFul api的方式从百度方获取
//有效期为一个月,可以存至数据库中然后从数据库中获取
type Authorizer interface {
Authorize(*Client) error
}

type Client struct {
ClientID string
Expand All @@ -31,17 +38,8 @@ type AuthResponseFailed struct {
ErrorDescription string `json:"error_description"` //错误描述信息,帮助理解和解决发生的错误。
}

//Authorizer 用于设置access_token
//可以通过RESTFul api的方式从百度方获取
//有效期为一个月,可以存至数据库中然后从数据库中获取
type Authorizer interface {
Authorize(client *Client) error
}

type DefaultAuthorizer struct{}

type RestApiAuthorizer DefaultAuthorizer

func (da DefaultAuthorizer) Authorize(client *Client) error {
resp, err := req.Post(VOICE_AUTH_URL, req.Param{
"grant_type": "client_credentials",
Expand All @@ -67,7 +65,11 @@ func (client *Client) Auth() error {
if client.AccessToken != "" {
return nil
}
return client.Authorizer.Authorize(client)

if err := client.Authorizer.Authorize(client); err != nil {
return err
}
return nil
}

func (client *Client) SetAuther(auth Authorizer) {
Expand Down
Binary file added example/16k.pcm
Binary file not shown.
Binary file removed example/hello.wav
Binary file not shown.
29 changes: 29 additions & 0 deletions example/version/ocr/ocr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"fmt"
"github.com/chenqinghe/baidu-ai-go-sdk/version/ocr"
"os"
)

const (
// This Api Key and Api Secret is just for example,
// you should get your own first.
APIKEY = "5RijeBzVjQ82uPx8gxGGfeNXlfRt7yH6"
APISECRET = "keiyq3oKrkYsSPUcrf0gtRKneeTxjuqV"
)

func main() {

client := ocr.NewOCRClient(APIKEY, APISECRET)

f, err := os.OpenFile("ocr.jpg", os.O_RDONLY, 0777)
if err != nil {
panic(err)
}
rs, err := client.GeneralRecognizeBasic(f)
if err != nil {
panic(err)
}
fmt.Println(string(rs))
}
File renamed without changes
34 changes: 10 additions & 24 deletions example/voice.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"github.com/chenqinghe/baidu-ai-go-sdk/voice"
"log"
"os"
"io/ioutil"
"encoding/base64"
"fmt"
)

Expand All @@ -24,7 +22,7 @@ func TextToSpeech() {
log.Fatal(err)
}

f, err := os.OpenFile("hello.mp3", os.O_CREATE|os.O_WRONLY, 0777)
f, err := os.OpenFile("hello.mp3", os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
Expand All @@ -43,30 +41,18 @@ func SpeechToText() {
log.Fatal(err)
}

f, err := os.OpenFile("hello.wav", os.O_RDONLY, 0666)
f, err := os.OpenFile("16k.pcm", os.O_RDONLY, 0666)
if err != nil {
log.Fatal(err)
}

fi, err1 := ioutil.ReadAll(f)
if err1 != nil {
log.Fatal(err1)
}
afterBase64Str := base64.StdEncoding.EncodeToString(fi)
fiLen := len(fi)
param := voice.ASRParams{
Format: "wav",
Rate: 16000,
Channel: 1,
Cuid: "12312312112",
Token: client.AccessToken,
Lan: "zh",
Speech: afterBase64Str,
Len: fiLen,
}
rs, err2 := client.SpeechToText(param)
if err2 != nil {
log.Fatal(err2)

rs, err := client.SpeechToText(
f,
voice.Format("pcm"),
voice.Channel(1),
)
if err != nil {
log.Fatal(err)
}
fmt.Println(rs)
}
Expand Down
117 changes: 0 additions & 117 deletions ocr/general.go

This file was deleted.

Loading

0 comments on commit 77b25fa

Please sign in to comment.