REST api được dùng để nhận dạng 1 file hoàn chỉnh & nhận về kết quả nhận dạng cuối cùng.
Hiện tại API hỗ trợ 3 định dạng file audio: wav, mp3, PCM (phải gửi kèm thông tin audio trong request), sử dụng giao thức http POST với các thông tin như sau:
API URL: https://viettelgroup.ai/voice/api/asr/v1/rest/decode_file
Các tùy chọn cho request được chỉ định trong HEADER như sau:
'token': (string) token dùng để xác thực người dùng. Bỏ trống nếu bạn muốn request nặc danh.
Các tùy chọn cho request được chỉ định trong url parameter như sau:
'model': (string) mã mô hình nhận dạng.
Với định dạng PCM, client phải cung cấp đủ các thông tin về audio trong header như sau:
'sample_rate': (float) sample rate (tần số lấy mẫu) của file audio.
'format': (string) format của audio ví dụ S16LE là *signed 16 bit little endian* (tham khảo PCM format: https://trac.ffmpeg.org/wiki/audio%20types)
'num_of_channels': (integer) số channel của audio.
Request: multipart upload file với thông tin:
'name'='file', 'filename'=$FILE_PATH
curl --request POST --cacert $CERT_FILE -H "token: $YOUR_TOKEN" -F "file=@$PATH_TO_FILE" https://viettelgroup.ai/voice/api/asr/v1/rest/decode_file
Trong đó:
- CERT_FILE: đường dẫn đến file chứng chỉ của https://viettelgroup.ai (Nếu CURL của bạn đã cập nhật chứng chỉ này thì có thể bỏ qua).
- PATH_TO_FILE: đường dẫn đến file cần nhận dạng.
Nếu muốn nhận dạng file PCM, bạn phải cung cấp thêm các thông tin cần thiết vào Header như sau:
`-H "sample_rate:$SAMPLE_RATE" -H "format:$FORMAT" -H "num_of_channels:$CHANNELS"`
Trong đó:
- SAMPLE_RATE: sample rate (tần số lấy mẫu) của file audio.
- FORMAT: format của audio ví dụ S16LE là *signed 16 bit little endian* (tham khảo https://trac.ffmpeg.org/wiki/audio%20types)
- CHANNELS: số channel của audio
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Import the json library
import requests
url = "https://viettelgroup.ai/voice/api/asr/v1/rest/decode_file"
headers = {
'token': 'anonymous',
#'sample_rate': 16000,
#'format':'S16LE',
#'num_of_channels':1,
#'asr_model': 'model code'
}
s = requests.Session()
files = {'file': open($AUDIO_PATH,'rb')}
response = requests.post(url,files=files, headers=headers, verify=$CERT_PATH)
print(response.text)
Trong đó: