Real-time Speech Recognition (Streaming)
1. Introduction
A service that converts voice data into text and transmits converted text results to the user in real-time with minimal latency. This API enables the development of applications or the establishment of automatic voice-to-text conversion services using text obtained from voice data.
WARNING
⚠ Songs or audio with loud background music are not supported.
2. Example
Below is a simple usage example, which describes creating a session token and sending requests to a streaming endpoint to receive converted text results using SSE.
1) Python Example
# This code does not work until the requests, requests-sse package is installed. <CopyButton /><EmailFormButton />
import base64
import concurrent.futures
import json
import requests
from requests_sse import EventSource, InvalidStatusCodeError, InvalidContentTypeError
HOST = 'https://apis.daglo.a'
API_TOKEN = '<API_TOKEN>'
def get_session_token():
headers = {'Authorization': f'Bearer {API_TOKEN}'}
return requests.get(HOST + "/stt/v1/stream/sessionTokens", headers=headers).json()
def send_audio_stream(audio_stream: bytes, sid: str, s_token: str):
headers = {'Authorization': f'Bearer {s_token}', 'Content-Type': 'application/json'}
audio_str = base64.b64encode(audio_stream).decode('utf-8')
data = { 'sessionId': sid, 'channel': 0, 'file': audio_str }
res = requests.post(HOST + "/stt/v1/stream/recognize", headers=headers, json=data)
def get_audio_stream(sid: str, s_token: str):
headers = { 'Authorization': f'Bearer {s_token}' }
with EventSource(HOST + f"/stt/v1/stream/sse/{sid}", timeout=30, headers=headers) as event_source:
try:
for event in event_source:
print(json.loads(event.data))
except InvalidStatusCodeError:
pass
except InvalidContentTypeError:
pass
except requests.RequestException:
pass
if __name__ == '__main__':
# 1. Prepare Audio Stream.
sample_audio_stream = requests.get('https://storage.googleapis.com/bkt-actionpower-examples/audio/actionpower_hello.wav').content
# 2. Acquire Session Token.
res = get_session_token()
sid = res['sessionId']
s_token = res['sessionToken']
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
# 3. Send the audio stream to POST Endpoint.
future = executor.submit(send_audio_stream, sample_audio_stream, sid, s_token)
# 4. At the same time, real-time STT results are received via SSE.
get_audio_stream(sid, s_token)Print Output
{'sessionId': '9070fe6d-c34e-4d45-8e68-11d9f944711', 'channel': 0, 'timestamp': 1724129309929, 'startTime': 1724129309929, 'sttResult': {'transcript': '안녕하세요. 액션파워입니다. 음성 인식의 선두 주자 액션파워의 기술을', 'isFinal': False}3. Instructions
1) Getting an API Key
- Create an account in the API console.
- Go to the token menu and issue a new token.
- Copy the issued token information and use it as an authentication token when requested.
2) Make a request
For more API information, please refer to the API Reference and the Real-Time Speech Transcription.
a. Getting session token
- Issue tokens required for real-time requests at the specified endpoint(Get stream STT session token).
GET https://apis.daglo.ai/stt/v1/stream/sessionTokensb. Transmitting real-time audio
- Send real-time audio chunks to the specified endpoint(Send audio chunks to transcribe) to request text conversion.
POST https://apis.daglo.ai/stt/v1/stream/recognizec. Refreshing session token
- Extend a token's permission by requesting a token reissue to the specified endpoint (Refresh stream STT session token) after 1 hour.
GET https://apis.daglo.ai/stt/v1/stream/refreshSessionTokens3) Getting a response
a. Get a real-time text stream
- Get real-time text results as a stream from the specified endpoint (Get audio transcription stream).
GET https://apis.daglo.ai/stt/v1/stream/sse/{sid}Update history
- 20240902 ver1.0 API document has been created.