SDK
| Languages/Frameworks | One-sentence Recognition Real-time Speech Transcription | Audio File Transcription |
|---|---|---|
| Vue | To be done | N/A |
| JavaScript | To be done | N/A |
| Android | To be done | N/A |
| C++ | To be done | N/A |
| Java | Download | N/A |
| Python | Download | Example code can be found below |
Note:
In the source code, Real-Time Speech Transcription is represented by
Transcriber, and One-sentence Recognition is represented byRecognizer. Please refer to these as needed.The Audio File Transcription service is provided as a standard HTTP interface, so no SDK is offered. You can develop the integration based on the interface protocol.
Audio File Transcription (Form-data) Example Codes for Python
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import time
import requests
from urllib3 import encode_multipart_formdata
host = 'http://127.0.0.1' #Server IP
port = 7100
#Set parameters
params = {
"file": ("filename", open('d:/test.wav', 'rb').read()),
'lang_type': 'ja-JP',
'sample_rate': 16000,
'format': 'wav',
'enable_inverse_text_normalization': True,
'paragraph_condition': 300, #Paragraph characters count
########## Configure as following for a far-field recording
#'max_sentence_silence': 3000,
#'gain': 5,
#'decode_silence_segment': True
}
encode_data = encode_multipart_formdata(params)
data = encode_data[0]
headers = {'Content-Type': encode_data[1], 'Request-Index': '0'}
request_url = f'{host}:{port}/request'
#Create an Audio File Transcription task
response = requests.post(request_url, data=data, headers=headers)
task_id = response.json()['data']['task_id']
get_result_url = f'{host}:{port}/getResult?task_id={task_id}'
start_time = time.time()
#Poll to get transcription results
while True:
formatted_time = time.strftime('%H:%M:%S', time.gmtime(time.time() - start_time))
data = requests.get(get_result_url).json()
if data['status'] == '00000':
print(f'\r{formatted_time} Processing... 100%', end='')
break
elif data['status'] == '20302':
progress = data['data']['progress']
#Processing
if progress > 0:
print(f'\r{formatted_time} Processing... {progress}%' + ' ' * 25, end='')
#Queuing
elif progress < 0:
print(f'\r{formatted_time} Waiting in queqe, with {-progress} task(s) ahead.', end='')
#Processing failed
else:
print('\n',data)
break
#Query the results again after 1 second
time.sleep(1)
else:
print('\n',data)
break
data_dict = dict()
print('\n')
#Print the result
for i in data['data']:
paragraph = i.get("paragraph", 0)
data_dict[paragraph] = data_dict.get(paragraph, '') + ' ' + i['transcript']
for seg_index, result in data_dict.items():
print(f'\t{result}')