AutoCaptcha.pro cung cấp API giúp chuyển đổi file audio (MP3/WAV) thành văn bản. Bạn có thể gửi dữ liệu dưới dạng base64 hoặc link URL. Kết quả trả về nằm trong trường captcha
.
1) Thông tin API
- Endpoint:
POST https://autocaptcha.pro/apiv3/process
- Content-Type:
application/json
- Tham số:
key
: API keytype
:speechtotext
body
: base64 audio hoặc URL audio
Ví dụ Request
{
"key": "YOUR_API_KEY",
"type": "speechtotext",
"body": "https://example.com/otp_6digits.mp3"
}
Ví dụ Response
{
"success": true,
"message": "Thành công",
"captcha": "119806",
}
Trường captcha
chính là chuỗi văn bản đã nhận dạng.
2) Code Python gọi API
Cách 1: Gửi URL audio
import requests
API_URL = "https://autocaptcha.pro/apiv3/process"
API_KEY = "YOUR_API_KEY"
def speech_to_text(api_key, body_value):
payload = {
"key": api_key,
"type": "speechtotext",
"body": body_value
}
resp = requests.post(API_URL, json=payload, timeout=(5, 30))
resp.raise_for_status()
data = resp.json()
return data.get("captcha")
if __name__ == "__main__":
captcha_from_url = speech_to_text(API_KEY, "https://example.com/otp_6digits.mp3")
print(captcha_from_url)
Cách 2: Gửi file local dạng base64
import base64
import requests
API_URL = "https://autocaptcha.pro/apiv3/process"
API_KEY = "YOUR_API_KEY"
def audio_file_to_base64(path):
with open(path, "rb") as f:
return base64.b64encode(f.read()).decode("utf-8")
def speech_to_text(api_key, body_value):
payload = {
"key": api_key,
"type": "speechtotext",
"body": body_value
}
resp = requests.post(API_URL, json=payload, timeout=(5, 30))
resp.raise_for_status()
data = resp.json()
return data.get("captcha")
if __name__ == "__main__":
base64_audio = audio_file_to_base64("sample.wav")
captcha_from_file = speech_to_text(API_KEY, base64_audio)
print(captcha_from_file)
3) Tổng kết
- Endpoint:
/apiv3/process
vớitype: speechtotext
. body
nhận URL hoặc base64.- Kết quả nằm trong trường
captcha
.