跳到主要内容

🇺🇸 英语语音转文本 (ASR) 基础版

1 IC每60秒
✅ 活跃🎙️ 语音
iApp Text to Speech API

试用演示

Example File (Click to try)

Selected: vc-demo.mp3

入门

先决条件

  • 来自 iApp Technology 的 API 密钥
  • 支持格式的音频文件
  • 最长文件时长:不超过 10 小时

主要功能

  • 从音频文件中提取文本
  • 支持多说话人对话的说话人分离
  • 支持多种音频格式
  • 带时间戳的高质量转录

安全与合规

  • API 密钥认证
  • 符合 GDPR 和 PDPA

API 端点

端点方法描述费用
/v3/store/speech/speech-to-text/base/en
旧版: /asr/v3/en
POST将英语语音转换为文本(基础模型)每 60 秒 1 IC

API 用法

支持的文件格式

API 支持以下音频和视频文件格式:

  • 音频:.mp3, .wav, .m4a, .aac, .aif, .cda, .flac, .mid, .ogg, .wma

端点: POST /v3/store/speech/speech-to-text/base/en

标头:

  • Content-Type: multipart/form-data
  • apikey: 您的 API 密钥用于身份验证

表单参数:

参数类型必填默认值描述
file文件-要转录的音频文件
prompt字符串"base"要使用的提示模板
chunk_size整数20用于处理音频块的秒数大小

示例请求:

curl -X POST "https://api.iapp.co.th/v3/store/speech/speech-to-text/base/en" \
-H "Content-Type: multipart/form-data" \
-H "apikey: YOUR_API_KEY" \
-F "file=@/path/to/your/audio.mp3" \
-F "prompt=base" \
-F "chunk_size=20"

示例响应:

{
"output": [
{
"text": "Transcribed text from segment one.",
"start": 0.0,
"end": 5.28,
"speaker": "SPEAKER_00",
"segment": 0
},
{
"text": "Transcribed text from segment two.",
"start": 5.28,
"end": 10.56,
"speaker": "SPEAKER_01",
"segment": 1
}
],
"audio_duration_in_seconds": 60.5,
"uploaded_file_name": "example.mp3",
"processing_time_in_seconds": 12.34,
"use_asr_pro": false,
"asr_pro_is_used": false,
"iapp": {
"seconds": 60.5
}
}

响应状态码

  • 200 OK: 请求成功
  • 400 Bad Request: 请求无效(例如,未上传文件,不支持的文件格式)
  • 404 Not Found: 未找到任务 ID
  • 500 Internal Server Error: 处理失败,服务器错误

注意事项

  • 支持说话人分离,分段包含说话人 ID 和时间戳信息。

代码示例

Curl

curl -X POST https://api.iapp.co.th/v3/store/speech/speech-to-text/base/en \
-H "apikey: YOUR_API_KEY" \
-F "file=@/path/to/audio.mp3"

Python 示例

import requests

def transcribe_audio(file_path, api_key):
url = "https://api.iapp.co.th/v3/store/speech/speech-to-text/base/en"
headers = {"apikey": api_key}

files = {"file": open(file_path, "rb")}
data = {
"prompt": "base",
"chunk_size": 20
}

response = requests.post(url, headers=headers, files=files, data=data)

if response.status_code == 200:
return response.json()
else:
return f"Error: {response.status_code}, {response.text}"

JavaScript 示例

async function transcribeAudio(filePath, apiKey) {
const url = "https://api.iapp.co.th/v3/store/speech/speech-to-text/base/en"

const formData = new FormData()
formData.append("file", await fetch(filePath).then((r) => r.blob()))
formData.append("prompt", "base")
formData.append("chunk_size", "20")

const response = await fetch(url, {
method: "POST",
headers: {
apikey: apiKey,
},
body: formData,
})

if (response.ok) {
return await response.json()
} else {
throw new Error(`Error: ${response.status}, ${await response.text()}`)
}
}

PHP 示例

function transcribe_audio($file_path, $api_key) {
$url = "https://api.iapp.co.th/v3/store/speech/speech-to-text/base/en";

$curl = curl_init();

$post_data = [
'file' => new CURLFile($file_path),
'prompt' => 'base',
'chunk_size' => '20'
];

curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post_data,
CURLOPT_HTTPHEADER => [
"apikey: $api_key"
]
]);

$response = curl_exec($curl);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

if ($status_code === 200) {
return json_decode($response, true);
} else {
return "Error: $status_code, $response";
}
}

// Usage
$result = transcribe_audio("path/to/audio.mp3", "YOUR_API_KEY");
print_r($result);

Swift 示例

import Foundation

func transcribeAudio(filePath: String, apiKey: String, completion: @escaping (Result<[String: Any], Error>) -> Void) {
let url = URL(string: "https://api.iapp.co.th/v3/store/speech/speech-to-text/base/en")!

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue(apiKey, forHTTPHeaderField: "apikey")

let boundary = UUID().uuidString
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

let fileURL = URL(fileURLWithPath: filePath)
guard let fileData = try? Data(contentsOf: fileURL) else {
completion(.failure(NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Could not load file"])))
return
}

var body = Data()
let filename = fileURL.lastPathComponent

// Add file
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"file\"; filename=\"\(filename)\"\r\n".data(using: .utf8)!)
body.append("Content-Type: audio/mpeg\r\n\r\n".data(using: .utf8)!)
body.append(fileData)
body.append("\r\n".data(using: .utf8)!)

// Add prompt
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"prompt\"\r\n\r\n".data(using: .utf8)!)
body.append("base".data(using: .utf8)!)
body.append("\r\n".data(using: .utf8)!)

// Add chunk_size
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"chunk_size\"\r\n\r\n".data(using: .utf8)!)
body.append("20".data(using: .utf8)!)
body.append("\r\n".data(using: .utf8)!)

body.append("--\(boundary)--\r\n".data(using: .utf8)!)

request.httpBody = body

URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
completion(.failure(error))
return
}

guard let data = data else {
completion(.failure(NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "No data received"])))
return
}

do {
if let json = try JSONSerialization.jsonObject(with: data) as? [String: Any] {
completion(.success(json))
} else {
completion(.failure(NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Invalid JSON format"])))
}
} catch {
completion(.failure(error))
}
}.resume()
}

// Usage
transcribeAudio(filePath: "path/to/audio.mp3", apiKey: "YOUR_API_KEY") { result in
switch result {
case .success(let json):
print(json)
case .failure(let error):
print("Error: \(error)")
}
}

Kotlin 示例

import okhttp3.*
import java.io.File
import java.io.IOException

fun transcribeAudio(filePath: String, apiKey: String, callback: (Result<String>) -> Unit) {
val client = OkHttpClient()
val file = File(filePath)

val requestBody = MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart(
"file",
file.name,
RequestBody.create(MediaType.parse("audio/*"), file)
)
.addFormDataPart("prompt", "base")
.addFormDataPart("chunk_size", "20")
.build()

val request = Request.Builder()
.url("https://api.iapp.co.th/v3/store/speech/speech-to-text/base/en")
.header("apikey", apiKey)
.post(requestBody)
.build()

client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
callback(Result.failure(e))
}

override fun onResponse(call: Call, response: Response) {
if (response.isSuccessful) {
callback(Result.success(response.body()?.string() ?: ""))
} else {
callback(Result.failure(IOException("Error: ${response.code()} ${response.message()}")))
}
}
})
}

Java 示例

import java.io.File;
import java.io.IOException;
import okhttp3.*;

public class ASRApiClient {

public static void transcribeAudio(String filePath, String apiKey, Callback callback) {
OkHttpClient client = new OkHttpClient();
File file = new File(filePath);

RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart(
"file",
file.getName(),
RequestBody.create(MediaType.parse("audio/*"), file)
)
.addFormDataPart("prompt", "base")
.addFormDataPart("chunk_size", "20")
.build();

Request request = new Request.Builder()
.url("https://api.iapp.co.th/v3/store/speech/speech-to-text/base/en")
.header("apikey", apiKey)
.post(requestBody)
.build();

client.newCall(request).enqueue(callback);
}

public static void main(String[] args) {
transcribeAudio("path/to/audio.mp3", "YOUR_API_KEY", new Callback() {
@Override
public void onFailure(Call call, IOException e) {
System.err.println("Error: " + e.getMessage());
}

@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
System.out.println(response.body().string());
} else {
System.err.println("Error: " + response.code() + " " + response.message());
}
}
});
}
}

Dart (Flutter) 示例

import 'dart:io';
import 'package:http/http.dart' as http;

Future<Map<String, dynamic>> transcribeAudio(String filePath, String apiKey) async {
var uri = Uri.parse('https://api.iapp.co.th/v3/store/speech/speech-to-text/base/en');

var request = http.MultipartRequest('POST', uri);
request.headers['apikey'] = apiKey;

request.files.add(await http.MultipartFile.fromPath(
'file',
filePath,
));

request.fields['prompt'] = 'base';
request.fields['chunk_size'] = '20';

try {
var response = await request.send();
var responseData = await http.Response.fromStream(response);

if (response.statusCode == 200) {
return jsonDecode(responseData.body);
} else {
throw Exception('Failed to transcribe: ${response.statusCode} ${responseData.body}');
}
} catch (e) {
throw Exception('Error transcribing file: $e');
}
}

定价

操作生产路径旧版路径IC 费用单位本地部署
英语语音转文本(基础版)/v3/store/speech/speech-to-text/base/en/asr/v3/en1 IC每 60 秒联系我们