Skip to main content

ASR Service Development Integration Guide

1. Preparation Before Integration

1.1 Prerequisites

  • Registration with Player Network Console is completed, and business project creation is done.
  • If SDK integration is used, the client Player Network SDK version must be 1.32 or above.

1.2 Choose Integration Method

Integration MethodApplicable ScenariosIntegration FeaturesSecurity Notes
SDK Integration (Recommended)Business has already integrated with Player Network SDK, and the client can directly call SDK capabilities.Short integration path, suitable for real-time in-game features.The client uses only the parameters required by the SDK and must not store secret.
API IntegrationOnly integrate the ASR Service, or invoke centrally via the game backend.Facilitates unified authentication, rate limiting, log audit, and business encapsulation.secret is only stored in a trusted backend or key management system.

1.3 Audio and Language Preparation

Preparation ItemDescriptionRecommendation
Language codeASR recognition language types, such as zh, en.Set according to the player's current language or business scenario; if uncertain, it should be clearly configured by the backend/management console.
Audio formatSupports WAV and GVoice Opus.audioFormat: 1-WAV, 2-GVoice Opus.The client recording format must be consistent with audioFormat.
Audio path/fileSDK side uses local VoicePath; API file upload uses the data Part.Verify file exists, is readable, and that size and duration are reasonable before upload.
Timestampapplication/json protocol requires timeStamp.start/end.For issue location in live broadcast or segment recognition scenarios.

2. Management Console Operations

  1. When you first enter the ASR Service, click "Try it for free now" to complete ASR Service feature initialization.

ASR Service Feature Initialization Entry

  1. For API integration, go to the "Project Info" to configure the ASR Service API whitelist and fill in your game backend's egress IP into the whitelist and save.

ASR Service API Whitelist / Scenario Configuration Entry

3. Backend API Integration

3.1 Protocol Selection

ProtocolContent-TypeAudio Input MethodApplicable ScenarioNotes
Protocol 1application/jsonThe audioFile field passes base64 encoded PCM audio data.Esports live streaming scenario.Must pass appId, audioFile, gameCode, srcLang, timeStamp, and traceId.
Protocol 2multipart/form-datameta Part passes JSON configuration; data Part passes audio binary file.In-game voice recognition from Player, client uploading WAV/GVoice Opus file.Content-Type of both meta and data Parts will be checked and must be filled in as required.

3.2 API Information

When calling the ASR Service API from the backend, select the corresponding full address according to the current deployment environment. The API path is /api/v2/speechai/asr.

EnvironmentFull API AddressDescription
Tencent Cloud Test environmenthttps://asr-test.intlgame.com/api/v2/speechai/asrFor use in Tencent Cloud test environment.
Jakarta Test environmenthttps://ai-test.intlgame.com/api/v2/speechai/asrFor use in Jakarta test environment.
Jakarta Production environmenthttps://speechai.intlgame.com/api/v2/speechai/asrFor use in production environment.
ProjectDescription
API PathPOST \<API domain>/api/v2/speechai/asr
Content-Typemultipart/form-data or application/json
AuthorizationBearer \<token>
Authentication MethodJWT, signature algorithm HS256; payload.data.account must be consistent with appId.
Feature DescriptionSpeech recognition interface supports both base64 encoded PCM audio data and file upload audio.

3.3 application/json Request Parameters

ParameterTypeMandatoryDescription
appIdstringYesappId assigned by the Admin.
audioFilestringYesbase64 encoded PCM audio data.
gameCodestringYesBusiness code identifying the business scenario; an incorrect value will result in an error.
srcLangstringYesTarget speech recognition language code, such as zh, en.
timeStampjson stringYesTimestamp information, including start, end.
traceIdstringYesUnique request ID, used to track requests.
gameLangstringNoPlayer game language, can be omitted if there is no Player.
systemLangstringNoPlayer's system language, can be omitted if there is no Player.
openIdstringNoUser ID, currently not in use.
sessionIdstringNoSession ID, currently not in use.

timeStamp Field

FieldTypeMandatoryDescription
startfloat64YesAudio segment start time.
endfloat64YesAudio segment end time.
application/json Request Example
POST /api/v2/speechai/asr HTTP/1.1
Content-Type: application/json
Authorization: Bearer <token>

{
"appId": "<app-id>",
"audioFile": "<base64 encoded PCM audio data>",
"traceId": "asr-json-001",
"srcLang": "zh",
"gameCode": "<game-code>",
"timeStamp": {
"start": 1672531200,
"end": 1672531260
}
}

3.4 multipart/form-data Request Parameters

Part NameContent-TypeRequiredDescription
metaapplication/jsonYesJSON configuration, describing basic information such as appId, audioFormat, gameCode, language, and traceId.
dataapplication/octet-streamYesAudio binary file, currently supports WAV and GVoice Opus.

meta Parameters

ParameterTypeRequiredDescription
appIdstringYesappId assigned by the admin.
audioFormatintYesAudio format: 1-WAV, 2-GVoice Opus.
gameCodestringYesBusiness code identifying the business scenario.
traceIdstringYesUnique request ID, used to track requests.
srcLangstringNoTarget speech recognition language, such as zh, en; usually optional for in-game scenarios, more for e-sports live streaming.
gameLangstringNoPlayer game language.
systemLangstringNoPlayer system language.
openIdstringNoUser ID, currently not in use.
sessionIdstringNoSession ID, currently not in use.
timeStampjson stringNoTimestamp information, including start, end.
multipart/form-data Request Example
POST /api/v2/speechai/asr HTTP/1.1
Content-Type: multipart/form-data; boundary=----boundary
Authorization: Bearer <token>

------boundary
Content-Disposition: form-data; name="meta"
Content-Type: application/json

{
"appId": "<app-id>",
"audioFormat": 1,
"traceId": "asr-file-001",
"srcLang": "en",
"gameLang": "en",
"systemLang": "en",
"gameCode": "<game-code>"
}
------boundary
Content-Disposition: form-data; name="data"; filename="voice.wav"
Content-Type: application/octet-stream

(binary)
------boundary--

3.5 Response Handling

Response FieldTypeDescriptionHandling Recommendation
retCodeintReturn code, 0 means success.If not 0, enter error handling and log reporting.
messagestringReturn message.For log records, not recommended for direct display to players.
traceIdstringRequest tracking ID.Provide to PNT support for troubleshooting.
resultobjectASR recognition result, returned only when successful.Read result.text as the full recognized transcript.
result.startfloat64Audio segment start time.Used for streaming or segment recognition scenarios.
result.endfloat64Audio segment end time.Used for streaming or segment recognition scenarios.
result.textstringFull recognized text content.Display or enter follow-up translation/review process.
result.words[]WordDetailed word-level information list.Used for subtitle timeline, confidence, or speaker display; ignore if empty.
Word parameter fieldTypeDescription
textstringText content of the individual word.
startfloat64The start time of the word in the audio (seconds).
endfloat64The end time of the word in the audio (seconds).
scorefloat64Confidence score of word recognition.
speakerstringSpeaker identifier, used to distinguish different speakers.
Success Response Example
{
"retCode": 0,
"message": "success",
"traceId": "29d7b34e-3521-4f16-9c5a-12b36c466382",
"result": {
"start": 1770780974,
"end": 1770780980.017,
"text": "Hello World!",
"words": null
}
}

3.6 Error Handling Recommendations

Error TypePossible CauseHandling Suggestion
Authentication failedToken expired, signature error, or appId does not match token account.Regenerate token; check appId/secret; verify Authorization header format.
Parameter errorMissing appId, gameCode, traceId, audioFile; unsupported audioFormat; incorrect Part Content-Type for meta/data.Verify required fields per protocol; explicitly set Part Content-Type for multipart requests.
Audio format errorAudio is not WAV/GVoice Opus or failed base64 decoding.Verify format before client upload; server should log file type and size.
Abnormal audio durationAudio is empty, too short, too long, or duration does not meet service requirements.Client limits recording duration; backend adds pre-validation.
Recognition is empty or noisyAudio has excessive noise, no human voice, or triggers noise filtering.Prompt player to re-record on frontend; denoise or limit environmental noise as needed.
Internal Service ErrorASR service or dependency exception.Retry briefly; if still fails, contact PNT support and provide traceId.

4. Client SDK Integration

Version requirement

SDK integration for ASR Service requires Player Network SDK version 1.32 or above.Versions below 1.32 do not support the related capability; please upgrade the SDK first.

4.1 Invocation Process

  1. Ensure the client has integrated Player Network SDK and completed login state initialization.
  2. Record or obtain a local audio file, ensuring the format is WAV or GVoice Opus.
  3. Construct the INTLTranslatorVoiceV2Req request struct, filling fields such as VoicePath, AudioFormat, GameCode, and TraceId.
  4. Call the SDK's encapsulated audio translation/ASR interface to submit the request.Use the actual method name according to your SDK version documentation.
  5. Read asrRsp from the INTLTranslatorResult callback, and give priority to parsing result.text according to the ASR V2 structure.
  6. Display the recognized text or proceed with text translation, sensitive word review, chat sending, and other business processes.

4.2 Description of INTLTranslatorVoiceV2Req Fields

FieldTypeRequiredDescriptionFilling Suggestion
VoicePathStringYesAudio file path.Ensure the file exists and the client has read permissions.
AudioFormatIntegerYesCurrently supports WAV and GVoice Opus: 1-WAV, 2-GVoice Opus.Fill in according to actual file format; do not mix them.
GameCodeStringYesgameCode assigned to the game by AI Translation Service.Use the value obtained in the admin scenario switch.
SessionIdStringNoSession ID for streaming ASR.Not required for non-streaming/regular file recognition.
GameLanguageStringNoGame language setting.Can be set to the player's current game language.
ExtInfoStringNoAdditional information.You can enter a JSON string.
TraceIdStringYesUnique request ID for tracking purposes.It is recommended to generate a unique UUID for each request.
Client ASR V2 Request Sample (Pseudocode; actual SDK method names may vary)
INTLTranslatorVoiceV2Req req;
req.VoicePath = "<local-voice-file.wav>";
req.AudioFormat = 1; // 1-WAV, 2-GVoice Opus
req.GameCode = "<game-code>";
req.SessionId = "";
req.GameLanguage = "zh";
req.ExtInfo = "";
req.TraceId = "client-asr-trace-001";

// SDK.AudioTranslateV2(req, OnTranslatorResult);

4.3 asrRsp Callback Handling

  • ASR results are returned in asrRsp; the game side needs to parse them itself.
  • It is recommended to read asr_rsp.result.text as the recognition result in ASR V2.
  • start, end, and words are mainly used for streaming or subtitle scenarios; can be ignored for normal in-game speech-to-text.
  • Only display the recognized text when callback retCode is 0; if not 0, prompt to re-record or try again later.
asrRsp V2 Core structure example
{
"ret": 0,
"msg": "success",
"translator_rsp": "",
"asr_rsp": {
"retCode": 0,
"message": "success",
"traceId": "traceId",
"result": {
"text": "Hello World!",
"start": 0,
"end": 0,
"words": null
}
}
}

5. Integration and Acceptance Testing

5.1 Acceptance Checklist

Checklist ItemPass CriteriaProblem Location Field
Feature InitializationAdmin console has completed ASR Service initialization.Project ID, appId
gameCodeThe provided gameCode is consistent with the admin scenario.gameCode, traceId
Protocol SelectionUse application/json for base64. Use multipart/form-data for file upload.Content-Type, request body
Audio FormatWAV/GVoice Opus consistent with audioFormat.audioFormat, file extension, audio header
multipart partmeta is application/json; data is application/octet-stream.Part Content-Type
Recognition resultIf successful, result.text or asr_rsp.result.text contains content.retCode, message, traceId
Empty audio/noiseIf there is no human voice or the scenario is noisy, prompt to re-record.retCode, audio duration, traceId
Exception fallbackAuthentication, parameters, formats, and service exceptions all have business prompts.retCode, message, traceId

5.2 Pre-launch confirmation

  • Production domain, whitelist, and rate limit configuration confirmed.
  • Backend token expiration time is reasonable and supports automatic refresh.
  • Do not print secret, full token, or complete audio contents in logs.
  • Client supports fallback processes such as recording failure, recognition failure, and re-record.
  • Key error codes and traceId are integrated into monitoring alerts or issue reporting.
Client experience suggestions

Prompt the player to stay in a quiet environment before recording; display the duration during recording; show loading during upload and recognition; provide a "Record Again" option upon failure.

It is recommended to display the ASR recognized text to the player for confirmation before sending, to avoid sending misrecognized content directly.

6. Common Issues & Troubleshooting Recommendations

QuestionPossible CausesSolution
ASR reports parameter error after uploading fileIncorrect multipart meta/data part name or Content-Type.Confirm meta=application/json, data=application/octet-stream.
ASR recognition result is emptyNo valid voice detected in the audio, excessive noise, or abnormal recording permissions.The client should first locally verify the size/duration of the recording file; prompt the player to re-record.
ASR audio format errorUploaded format does not match audioFormat, or is not WAV/GVoice Opus.Use unified recording coding; send audioFormat=1 for WAV, audioFormat=2 for GVoice Opus.
Authentication failedToken missing, expired, signature error, or request body appId does not match token account.Regenerate token; check secret; confirm Authorization: Bearer \<token> format.
SDK callback invalid config / ret 91002Backend configuration missing.Please contact the Player Network Assistant to supplement the configuration.

Appendix: Backend integration pseudocode

Python Pseudocode: multipart/form-data calls ASR
import json
import time
import uuid

import jwt
import requests

app_id = "<app-id>"
secret = "<secret>"
api_url = "https://<api-domain>/api/v2/speechai/asr"

token = jwt.encode(
{
"data": {"account": app_id},
"exp": int(time.time()) + 300,
},
secret,
algorithm="HS256",
)

meta = {
"appId": app_id,
"audioFormat": 1,
"traceId": str(uuid.uuid4()),
"srcLang": "zh",
"gameLang": "zh",
"systemLang": "zh",
"gameCode": "<game-code>",
}

with open("voice.wav", "rb") as f:
files = {
"meta": (None, json.dumps(meta), "application/json"),
"data": ("voice.wav", f, "application/octet-stream"),
}
resp = requests.post(
api_url,
files=files,
headers={"Authorization": f"Bearer {token}"},
)

print(resp.json())