REST API for Mono (1) Channel
POST
Parameter Names | Description | Notes |
---|---|---|
apikey | Enter your apikey from https://ai.iapp.co.th | Required |
Parameter Names | Description | Notes |
---|---|---|
file | Speech Voice file in MP3 or WAV Format | Required |
diarization | Enable Speaker Diarization (true/false) | Optional (Default = True) |
When speaker diarization is enabled, it will return as follows:
Parameter Names | Description |
---|---|
speaker | Automatically generated ID for each voice. |
speech | Array of transcribed text with confidence score JSON object. Speech array can contains multiple transcribed text if there are silence periods. The transcribed text is splitted by silences (more than 1 sec) between speech. |
start_second | Beginning second of the speaker's speech. |
stop_second | Ending second of the speaker's speech. |
curl --location --request POST 'https://api.iapp.co.th/asr' \
--header 'apikey: {your api key}' \
--form '[email protected]"/Users/kobkrit/Desktop/ETC/2ppl.wav"'
[
{
"speaker": "SPEAKER_01",
"speech": [
{
"confidence": 0.9536809921264648,
"transcript": "สวัสดีค่ะฉันเสียงผู้ใหญ่ค่ะ"
}
],
"start_second": 1.2234375000000002,
"stop_second": 3.7715625
},
{
"speaker": "SPEAKER_00",
"speech": [
{
"confidence": 0.9589725732803345,
"transcript": "สวัสดีครับผมเสียงผู้ใหญ่ผู้ชายครับ"
}
],
"start_second": 5.0878125,
"stop_second": 8.159062500000001
}
]
JS/NodeJS
Python
Java
PHP
Objective C
Swift
Dart (Flutter)
var request = require('request');
var fs = require('fs');
var options = {
'method': 'POST',
'url': 'https://api.iapp.co.th/asr',
'headers': {
'apikey': '{your api key}'
},
formData: {
'file': {
'value': fs.createReadStream('/Users/kobkrit/Desktop/ETC/small.mp3'),
'options': {
'filename': 'small.mp3',
'contentType': null
}
}
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
Node
import requests
url = "https://api.iapp.co.th/asr"
payload={}
files=[
('file',('small.mp3',open('/Users/kobkrit/Desktop/ETC/small.mp3','rb'),'audio/mpeg'))
]
headers = {
'apikey': '{your api key}'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("file","small.mp3",
RequestBody.create(MediaType.parse("application/octet-stream"),
new File("/Users/kobkrit/Desktop/ETC/small.mp3")))
.build();
Request request = new Request.Builder()
.url("https://api.iapp.co.th/asr")
.method("POST", body)
.addHeader("apikey", "{your api key}")
.build();
Response response = client.newCall(request).execute();
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api.iapp.co.th/asr');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'apikey' => '{your api key}'
));
$request->addUpload('file', '/Users/kobkrit/Desktop/ETC/small.mp3', 'small.mp3', '<Content-Type Header>');
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
#import <Foundation/Foundation.h>
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.iapp.co.th/asr"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSDictionary *headers = @{
@"apikey": @"{your api key}"
};
[request setAllHTTPHeaderFields:headers];
NSArray *parameters = @[
@{ @"name": @"file", @"fileName": @"/Users/kobkrit/Desktop/ETC/small.mp3" }
];
NSString *boundary = @"----WebKitFormBoundary7MA4YWxkTrZu0gW";
NSError *error;
NSMutableString *body = [NSMutableString string];
for (NSDictionary *param in parameters) {
[body appendFormat:@"--%@\r\n", boundary];
if (param[@"fileName"]) {
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"; filename=\"%@\"\r\n", param[@"name"], param[@"fileName"]];
[body appendFormat:@"Content-Type: %@\r\n\r\n", param[@"contentType"]];
[body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSUTF8StringEncoding error:&error]];
if (error) {
NSLog(@"%@", error);
}
} else {
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"\r\n\r\n", param[@"name"]];
[body appendFormat:@"%@", param[@"value"]];
}
}
[body appendFormat:@"\r\n--%@--\r\n", boundary];
NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:postData];
[request setHTTPMethod:@"POST"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
dispatch_semaphore_signal(sema);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSError *parseError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
NSLog(@"%@",responseDictionary);
dispatch_semaphore_signal(sema);
}
}];
[dataTask resume];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
var semaphore = DispatchSemaphore (value: 0)
let parameters = [
[
"key": "file",
"src": "/Users/kobkrit/Desktop/ETC/small.mp3",
"type": "file"
]] as [[String : Any]]
let boundary = "Boundary-\(UUID().uuidString)"
var body = ""
var error: Error? = nil
for param in parameters {
if param["disabled"] == nil {
let paramName = param["key"]!
body += "--\(boundary)\r\n"
body += "Content-Disposition:form-data; name=\"\(paramName)\""
if param["contentType"] != nil {
body += "\r\nContent-Type: \(param["contentType"] as! String)"
}
let paramType = param["type"] as! String
if paramType == "text" {
let paramValue = param["value"] as! String
body += "\r\n\r\n\(paramValue)\r\n"
} else {
let paramSrc = param["src"] as! String
let fileData = try NSData(contentsOfFile:paramSrc, options:[]) as Data
let fileContent = String(data: fileData, encoding: .utf8)!
body += "; filename=\"\(paramSrc)\"\r\n"
+ "Content-Type: \"content-type header\"\r\n\r\n\(fileContent)\r\n"
}
}
}
body += "--\(boundary)--\r\n";
let postData = body.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.iapp.co.th/asr")!,timeoutInterval: Double.infinity)
request.addValue("{your api key}", forHTTPHeaderField: "apikey")
request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
semaphore.signal()
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}
task.resume()
semaphore.wait()
var headers = {
'apikey': '{your api key}'
};
var request = http.MultipartRequest('POST', Uri.parse('https://api.iapp.co.th/asr'));
request.files.add(await http.MultipartFile.fromPath('file', '/Users/kobkrit/Desktop/ETC/small.mp3'));
request.headers.addAll(headers);
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
print(await response.stream.bytesToString());
}
else {
print(response.reasonPhrase);
}
Last modified 7mo ago