API Documentation (REST API)

Postman Request

Request URL

Request Method

POST

Headers

Parameter Names
Description
Notes
apikey
Enter your apikey from https://ai.iapp.co.th
Required

Request Parameter (Form Data)

Parameter Names
Description
Notes
file
Speech Voice file in MP3 or WAV Format
Required

Return Values (JSON)

Parameter Names
Description
text
Transcribed Text

Sample Request

1
curl --location --request POST 'https://api.iapp.co.th/asr' \
2
--header 'apikey: {your api key}' \
3
--form '[email protected]"/Users/kobkrit/Desktop/ETC/small.mp3"'
Copied!

Sample Response

1
{
2
"text": "สวัสดีครับน้องไข่ต้มเสียงเด็กผู้ชายมาแล้วฮะ"
3
}
Copied!

Programming Languages Implementation Examples

JS/NodeJS
Python
Java
PHP
Objective C
Swift
Dart (Flutter)
1
var request = require('request');
2
var fs = require('fs');
3
var options = {
4
'method': 'POST',
5
'url': 'https://api.iapp.co.th/asr',
6
'headers': {
7
'apikey': '{your api key}'
8
},
9
formData: {
10
'file': {
11
'value': fs.createReadStream('/Users/kobkrit/Desktop/ETC/small.mp3'),
12
'options': {
13
'filename': 'small.mp3',
14
'contentType': null
15
}
16
}
17
}
18
};
19
request(options, function (error, response) {
20
if (error) throw new Error(error);
21
console.log(response.body);
22
});
23
Node
Copied!
1
import requests
2
3
url = "https://api.iapp.co.th/asr"
4
5
payload={}
6
files=[
7
('file',('small.mp3',open('/Users/kobkrit/Desktop/ETC/small.mp3','rb'),'audio/mpeg'))
8
]
9
headers = {
10
'apikey': '{your api key}'
11
}
12
13
response = requests.request("POST", url, headers=headers, data=payload, files=files)
14
15
print(response.text)
Copied!
1
OkHttpClient client = new OkHttpClient().newBuilder()
2
.build();
3
MediaType mediaType = MediaType.parse("text/plain");
4
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
5
.addFormDataPart("file","small.mp3",
6
RequestBody.create(MediaType.parse("application/octet-stream"),
7
new File("/Users/kobkrit/Desktop/ETC/small.mp3")))
8
.build();
9
Request request = new Request.Builder()
10
.url("https://api.iapp.co.th/asr")
11
.method("POST", body)
12
.addHeader("apikey", "{your api key}")
13
.build();
14
Response response = client.newCall(request).execute();
Copied!
1
<?php
2
require_once 'HTTP/Request2.php';
3
$request = new HTTP_Request2();
4
$request->setUrl('https://api.iapp.co.th/asr');
5
$request->setMethod(HTTP_Request2::METHOD_POST);
6
$request->setConfig(array(
7
'follow_redirects' => TRUE
8
));
9
$request->setHeader(array(
10
'apikey' => '{your api key}'
11
));
12
$request->addUpload('file', '/Users/kobkrit/Desktop/ETC/small.mp3', 'small.mp3', '<Content-Type Header>');
13
try {
14
$response = $request->send();
15
if ($response->getStatus() == 200) {
16
echo $response->getBody();
17
}
18
else {
19
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
20
$response->getReasonPhrase();
21
}
22
}
23
catch(HTTP_Request2_Exception $e) {
24
echo 'Error: ' . $e->getMessage();
25
}
Copied!
1
#import <Foundation/Foundation.h>
2
3
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
4
5
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.iapp.co.th/asr"]
6
cachePolicy:NSURLRequestUseProtocolCachePolicy
7
timeoutInterval:10.0];
8
NSDictionary *headers = @{
9
@"apikey": @"{your api key}"
10
};
11
12
[request setAllHTTPHeaderFields:headers];
13
NSArray *parameters = @[
14
@{ @"name": @"file", @"fileName": @"/Users/kobkrit/Desktop/ETC/small.mp3" }
15
];
16
17
NSString *boundary = @"----WebKitFormBoundary7MA4YWxkTrZu0gW";
18
NSError *error;
19
NSMutableString *body = [NSMutableString string];
20
21
for (NSDictionary *param in parameters) {
22
[body appendFormat:@"--%@\r\n", boundary];
23
if (param[@"fileName"]) {
24
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"; filename=\"%@\"\r\n", param[@"name"], param[@"fileName"]];
25
[body appendFormat:@"Content-Type: %@\r\n\r\n", param[@"contentType"]];
26
[body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSUTF8StringEncoding error:&error]];
27
if (error) {
28
NSLog(@"%@", error);
29
}
30
} else {
31
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"\r\n\r\n", param[@"name"]];
32
[body appendFormat:@"%@", param[@"value"]];
33
}
34
}
35
[body appendFormat:@"\r\n--%@--\r\n", boundary];
36
NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];
37
[request setHTTPBody:postData];
38
39
[request setHTTPMethod:@"POST"];
40
41
NSURLSession *session = [NSURLSession sharedSession];
42
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
43
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
44
if (error) {
45
NSLog(@"%@", error);
46
dispatch_semaphore_signal(sema);
47
} else {
48
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
49
NSError *parseError = nil;
50
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
51
NSLog(@"%@",responseDictionary);
52
dispatch_semaphore_signal(sema);
53
}
54
}];
55
[dataTask resume];
56
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
Copied!
1
import Foundation
2
#if canImport(FoundationNetworking)
3
import FoundationNetworking
4
#endif
5
6
var semaphore = DispatchSemaphore (value: 0)
7
8
let parameters = [
9
[
10
"key": "file",
11
"src": "/Users/kobkrit/Desktop/ETC/small.mp3",
12
"type": "file"
13
]] as [[String : Any]]
14
15
let boundary = "Boundary-\(UUID().uuidString)"
16
var body = ""
17
var error: Error? = nil
18
for param in parameters {
19
if param["disabled"] == nil {
20
let paramName = param["key"]!
21
body += "--\(boundary)\r\n"
22
body += "Content-Disposition:form-data; name=\"\(paramName)\""
23
if param["contentType"] != nil {
24
body += "\r\nContent-Type: \(param["contentType"] as! String)"
25
}
26
let paramType = param["type"] as! String
27
if paramType == "text" {
28
let paramValue = param["value"] as! String
29
body += "\r\n\r\n\(paramValue)\r\n"
30
} else {
31
let paramSrc = param["src"] as! String
32
let fileData = try NSData(contentsOfFile:paramSrc, options:[]) as Data
33
let fileContent = String(data: fileData, encoding: .utf8)!
34
body += "; filename=\"\(paramSrc)\"\r\n"
35
+ "Content-Type: \"content-type header\"\r\n\r\n\(fileContent)\r\n"
36
}
37
}
38
}
39
body += "--\(boundary)--\r\n";
40
let postData = body.data(using: .utf8)
41
42
var request = URLRequest(url: URL(string: "https://api.iapp.co.th/asr")!,timeoutInterval: Double.infinity)
43
request.addValue("{your api key}", forHTTPHeaderField: "apikey")
44
request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
45
46
request.httpMethod = "POST"
47
request.httpBody = postData
48
49
let task = URLSession.shared.dataTask(with: request) { data, response, error in
50
guard let data = data else {
51
print(String(describing: error))
52
semaphore.signal()
53
return
54
}
55
print(String(data: data, encoding: .utf8)!)
56
semaphore.signal()
57
}
58
59
task.resume()
60
semaphore.wait()
Copied!
1
var headers = {
2
'apikey': '{your api key}'
3
};
4
var request = http.MultipartRequest('POST', Uri.parse('https://api.iapp.co.th/asr'));
5
request.files.add(await http.MultipartFile.fromPath('file', '/Users/kobkrit/Desktop/ETC/small.mp3'));
6
request.headers.addAll(headers);
7
8
http.StreamedResponse response = await request.send();
9
10
if (response.statusCode == 200) {
11
print(await response.stream.bytesToString());
12
}
13
else {
14
print(response.reasonPhrase);
15
}
Copied!