---
title: "Live streaming recognition"
slug: "ai-application-service-clovaspeech-example02"
updated: 2026-09-17T09:35:47Z
published: 2026-09-17T09:35:47Z
canonical: "api.ncloud-docs.com/ai-application-service-clovaspeech-example02"
---
> ## Documentation Index
> Fetch the complete documentation index at: https://api.ncloud-docs.com/llms.txt
> Use this file to discover all available pages before exploring further.
# Live streaming recognition
Available in Classic and VPC
This document introduces live streaming examples from the CLOVA Speech service.
## Java
The following is a Java-based sample code for the API.
- Project Structure
```
├───pom.xml
│ │
└───src
│ ├───main
│ │ ├───java
│ │ │ └───com
│ │ │ └───example
│ │ │ └───grpc
│ │ │ GRpcClient.java
│ │ │
│ │ ├───proto
│ │ │ nest.proto
```
- pom.xml
```
4.0.0
com.example
clova-speech-grpc
1.0-SNAPSHOT
1.8
${java.version}
${java.version}
UTF-8
UTF-8
4.1.52.Final
1.35.0
3.14.0
io.grpc
grpc-netty
${grpc.version}
io.grpc
grpc-netty-shaded
${grpc.version}
io.grpc
grpc-protobuf
${grpc.version}
io.grpc
grpc-stub
${grpc.version}
org.projectlombok
lombok
true
1.18.12
kr.motd.maven
os-maven-plugin
1.6.1
org.apache.maven.plugins
maven-compiler-plugin
3.1
compile
compile
compile
testCompile
test-compile
testCompile
true
${project.build.sourceEncoding}
org.xolstice.maven.plugins
protobuf-maven-plugin
0.6.1
com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}
grpc-java
io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}
compile
compile-custom
```
- Java
```
package com.example.grpc;
import java.io.FileInputStream;
import java.util.concurrent.CountDownLatch;
import com.google.protobuf.ByteString;
import com.nbp.cdncp.nest.grpc.proto.v1.NestConfig;
import com.nbp.cdncp.nest.grpc.proto.v1.NestData;
import com.nbp.cdncp.nest.grpc.proto.v1.NestRequest;
import com.nbp.cdncp.nest.grpc.proto.v1.NestResponse;
import com.nbp.cdncp.nest.grpc.proto.v1.NestServiceGrpc;
import com.nbp.cdncp.nest.grpc.proto.v1.RequestType;
import io.grpc.ManagedChannel;
import io.grpc.Metadata;
import io.grpc.StatusRuntimeException;
import io.grpc.netty.NettyChannelBuilder;
import io.grpc.stub.MetadataUtils;
import io.grpc.stub.StreamObserver;
public class GRpcClient {
public static void main(String[] args) throws Exception {
CountDownLatch latch = new CountDownLatch(1);
ManagedChannel channel = NettyChannelBuilder
.forTarget("clovaspeech-gw.ncloud.com:50051")
.useTransportSecurity()
.build();
NestServiceGrpc.NestServiceStub client = NestServiceGrpc.newStub(channel);
Metadata metadata = new Metadata();
metadata.put(Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER),
"Bearer ${secretKey}");
client = MetadataUtils.attachHeaders(client, metadata);
StreamObserver responseObserver = new StreamObserver() {
@Override
public void onNext(NestResponse response) {
System.out.println("Received response: " + response.getContents());
}
@Override
public void onError(Throwable t) {
if(t instanceof StatusRuntimeException) {
StatusRuntimeException error = (StatusRuntimeException)t;
System.out.println(error.getStatus().getDescription());
}
latch.countDown();
}
@Override
public void onCompleted() {
System.out.println("completed");
latch.countDown();
}
};
StreamObserver requestObserver = client.recognize(responseObserver);
requestObserver.onNext(NestRequest.newBuilder()
.setType(RequestType.CONFIG)
.setConfig(NestConfig.newBuilder()
.setConfig("{\"transcription\":{\"language\":\"ko\"}}")
.build())
.build());
java.io.File file = new java.io.File("~/media/42s.wav");
byte[] buffer = new byte[32000];
int bytesRead;
FileInputStream inputStream = new FileInputStream(file);
while ((bytesRead = inputStream.read(buffer)) != -1) {
requestObserver.onNext(NestRequest.newBuilder()
.setType(RequestType.DATA)
.setData(NestData.newBuilder()
.setChunk(ByteString.copyFrom(buffer, 0, bytesRead))
.setExtraContents("{ \"seqId\": 0, \"epFlag\": false}")
.build())
.build());
}
requestObserver.onCompleted();
latch.await();
channel.shutdown();
}
}
```
## Python
The following is a Python-based sample code for the API.
```
import grpc
import json
import nest_pb2
import nest_pb2_grpc
AUDIO_PATH = "path/to/audio/file" #Enter the path to the audio file to be recognized. (PCM (headerless raw wave) format at 16 kHz, 1 channel, 16 bits per sample)
CLIENT_SECRET = "Long sentence recognition secretKey"
def generate_requests(audio_path):
# Initial setup request: Set up speech recognition
yield nest_pb2.NestRequest(
type=nest_pb2.RequestType.CONFIG,
config=nest_pb2.NestConfig(
config=json.dumps({"transcription": {"language": "ko"}})
)
)
# Open an audio file and read 32,000 bytes at a time
with open(audio_path, "rb") as audio_file:
while True:
chunk = audio_file.read(32000) # Read chunks of an audio file
if not chunk:
break # Exit the loop when there is no more data
yield nest_pb2.NestRequest(
type=nest_pb2.RequestType.DATA,
data=nest_pb2.NestData(
chunk=chunk,
extra_contents=json.dumps({"seqId": 0, "epFlag": False})
)
)
def main():
# Set up a secure gRPC channel to the CLOVA Speech server
channel = grpc.secure_channel(
"clovaspeech-gw.ncloud.com:50051",
grpc.ssl_channel_credentials()
)
stub = nest_pb2_grpc.NestServiceStub(channel) # Create a stub for NestService
metadata = (("authorization", f"Bearer {CLIENT_SECRET}"),) # Set up metadata with authentication tokens
responses = stub.recognize(generate_requests(AUDIO_PATH), metadata=metadata) # Call the recognize method with the generated request
try:
# Process responses from the server repeatedly
for response in responses:
print("Received response: " + response.contents)
except grpc.RpcError as e:
# Handle gRPC errors
print(f"Error: {e.details()}")
finally:
channel.close() # Close the channel when finished
if __name__ == "__main__":
main()
```