NVIDIA Riva Client
The `nvidia-riva-client` library provides Python client APIs for interacting with NVIDIA Riva speech AI services, including Automatic Speech Recognition (ASR), Text-to-Speech (TTS), and Neural Machine Translation (NMT). It enables developers to integrate advanced conversational AI capabilities into their applications. The current version is 2.25.1, with releases typically tied to major Riva platform updates, leading to a moderately frequent release cadence.
Common errors
-
grpc._channel._MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with: status = StatusCode.UNAVAILABLE
cause The Riva server is not running, is inaccessible, or the `RIVA_URI` is incorrect/firewalled. This indicates a network or server availability issue.fixVerify the Riva server is running and healthy. Check the `RIVA_URI` (e.g., `localhost:50051`, `your.server.ip:50051`) and ensure there are no firewall rules blocking the connection. If running in Docker, ensure ports are correctly mapped. -
ModuleNotFoundError: No module named 'riva.client'
cause The `nvidia-riva-client` package is not installed or the Python environment is incorrect.fixInstall the package using `pip install nvidia-riva-client`. Ensure you are running your script in the same Python environment where the package was installed. -
AttributeError: module 'riva.client' has no attribute 'NLPClient'
cause Attempting to use the NLP client, which has been removed in recent versions of the `nvidia-riva-client` library.fixThe NLP client was deprecated and removed in version 2.15.0 and later. If you need NLP capabilities, use `nvidia-nemo-client` or another dedicated NVIDIA NLP framework. -
ImportError: cannot import name 'RecognitionConfig' from 'riva.client'
cause This error often occurs if there's a version mismatch between `nvidia-riva-client` and its `grpcio` dependency, or if the installed `nvidia-riva-client` is corrupted/incomplete.fixTry reinstalling the client and its dependencies: `pip uninstall -y nvidia-riva-client grpcio && pip install nvidia-riva-client`. Ensure your Python version meets the `nvidia-riva-client` requirements (`>=3.7`).
Warnings
- breaking The `grpcio` dependency often requires specific versions to match the `nvidia-riva-client` version. Incompatible `grpcio` versions can lead to `ImportError` or `AttributeError` during runtime, particularly with protobuf definitions or gRPC channel initialization.
- breaking The NLP client APIs were deprecated and removed in Riva client versions starting from 2.15.0.
- gotcha Riva client versions are generally designed to be compatible with a specific range of Riva server versions. Mismatched client and server versions can lead to unexpected errors, `gRPC UNAVAILABLE` status codes, or incorrect API behavior.
- gotcha Authentication methods and metadata retrieval (e.g., `get_auth_metadata`) have seen updates across versions, which might break older authentication patterns.
Install
-
pip install nvidia-riva-client
Imports
- ASRClient
from riva.client import ASRClient
- TTSClient
from riva.client import TTSClient
- Auth
from riva.client.auth import Auth
from riva.client import Auth
- AudioEncoding
from riva.client import AudioEncoding
- RecognitionConfig
from riva.client import RecognitionConfig
Quickstart
import os
import riva.client
import time
import wave
# Configure Riva server connection
# Ensure RIVA_URI is set in your environment (e.g., 'localhost:50051' or a remote address)
# For authenticated connections, set RIVA_API_KEY if needed.
riva_uri = os.environ.get('RIVA_URI', 'localhost:50051')
# Simple WAV file for ASR (create a dummy one if not present)
dummy_audio_file = 'dummy_audio.wav'
if not os.path.exists(dummy_audio_file):
with wave.open(dummy_audio_file, 'wb') as wf:
wf.setnchannels(1)
wf.setsampwidth(2)
wf.setframerate(16000)
wf.writeframes(b'\x00' * 16000 * 2) # 1 second of silence
print(f"Created a dummy audio file: {dummy_audio_file}")
try:
# Establish authentication (if needed, otherwise Auth() is sufficient)
auth = riva.client.Auth(uri=riva_uri)
# Initialize ASR client
asr_client = riva.client.ASRClient(auth)
# Configure ASR recognition
config = riva.client.RecognitionConfig(
encoding=riva.client.AudioEncoding.LINEAR_PCM, # or FLAC, MULAW, etc.
sample_rate_hertz=16000,
language_code="en-US",
max_alternatives=1,
enable_automatic_punctuation=True,
)
# Perform ASR on a local audio file
print(f"Transcribing {dummy_audio_file} from Riva server at {riva_uri}...")
response = asr_client.recognize_file(dummy_audio_file, config)
# Print results
if response.results:
for result in response.results:
if result.alternatives:
print(f"Transcription: {result.alternatives[0].transcript}")
else:
print("No alternatives found for this segment.")
else:
print("No speech recognized in the audio.")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure the Riva server is running and accessible at the specified RIVA_URI.")