| 24 | return &zimu |
| 25 | } |
| 26 | func (z *ZIMU) StartConvert(link string) { |
| 27 | // 地域ID,固定值。 |
| 28 | const REGION_ID string = "cn-shanghai" |
| 29 | const ENDPOINT_NAME string = "cn-shanghai" |
| 30 | const PRODUCT string = "nls-filetrans" |
| 31 | const DOMAIN string = "filetrans.cn-shanghai.aliyuncs.com" |
| 32 | const API_VERSION string = "2018-08-17" |
| 33 | const POST_REQUEST_ACTION string = "SubmitTask" |
| 34 | const GET_REQUEST_ACTION string = "GetTaskResult" |
| 35 | // 请求参数 |
| 36 | const KEY_APP_KEY string = "appkey" |
| 37 | const KEY_FILE_LINK string = "file_link" |
| 38 | const KEY_VERSION string = "version" |
| 39 | const KEY_ENABLE_WORDS string = "enable_words" |
| 40 | // 响应参数 |
| 41 | const KEY_TASK string = "Task" |
| 42 | const KEY_TASK_ID string = "TaskId" |
| 43 | const KEY_STATUS_TEXT string = "StatusText" |
| 44 | const KEY_RESULT string = "Result" |
| 45 | // 状态值 |
| 46 | const STATUS_SUCCESS string = "SUCCESS" |
| 47 | const STATUS_RUNNING string = "RUNNING" |
| 48 | const STATUS_QUEUEING string = "QUEUEING" |
| 49 | var accessKeyId string = z.AK |
| 50 | var accessKeySecret string = z.AS |
| 51 | var appKey string = z.AppKey |
| 52 | var fileLink string = link |
| 53 | client, err := sdk.NewClientWithAccessKey(REGION_ID, accessKeyId, accessKeySecret) |
| 54 | if err != nil { |
| 55 | panic(err) |
| 56 | } |
| 57 | postRequest := requests.NewCommonRequest() |
| 58 | postRequest.Domain = DOMAIN |
| 59 | postRequest.Version = API_VERSION |
| 60 | postRequest.Product = PRODUCT |
| 61 | postRequest.ApiName = POST_REQUEST_ACTION |
| 62 | postRequest.Method = "POST" |
| 63 | mapTask := make(map[string]string) |
| 64 | mapTask[KEY_APP_KEY] = appKey |
| 65 | mapTask[KEY_FILE_LINK] = fileLink |
| 66 | // 新接入请使用4.0版本,已接入(默认2.0)如需维持现状,请注释掉该参数设置。 |
| 67 | mapTask[KEY_VERSION] = "4.0" |
| 68 | // 设置是否输出词信息,默认为false。开启时需要设置version为4.0。 |
| 69 | mapTask[KEY_ENABLE_WORDS] = "false" |
| 70 | task, err := json.Marshal(mapTask) |
| 71 | if err != nil { |
| 72 | panic(err) |
| 73 | } |
| 74 | postRequest.FormParams[KEY_TASK] = string(task) |
| 75 | postResponse, err := client.ProcessCommonRequest(postRequest) |
| 76 | if err != nil { |
| 77 | panic(err) |
| 78 | } |
| 79 | postResponseContent := postResponse.GetHttpContentString() |
| 80 | fmt.Println(postResponseContent) |
| 81 | if postResponse.GetHttpStatus() != 200 { |
| 82 | fmt.Println("录音文件识别请求失败,Http错误码: ", postResponse.GetHttpStatus()) |
| 83 | return |