Skip to content

Instantly share code, notes, and snippets.

@arnabdas
Last active July 4, 2022 05:38
Show Gist options
  • Save arnabdas/8c70a875109039a4e1c853c61007ec23 to your computer and use it in GitHub Desktop.
Save arnabdas/8c70a875109039a4e1c853c61007ec23 to your computer and use it in GitHub Desktop.
Simple Python function to connect with Riva
import io
import os
import librosa
from time import time
import numpy as np
import grpc
import requests
# TTS proto
import riva_api.riva_tts_pb2 as rtts
import riva_api.riva_tts_pb2_grpc as rtts_srv
import riva_api.riva_audio_pb2 as ra
load_dotenv()
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('text', type=str, help='text for speech synthesis')
parser.add_argument('--host', type=str, default='0.0.0.0',
help='server IP address')
args = parser.parse_args()
channel = grpc.insecure_channel(f'{os.getenv(args.host)}:50051')
riva_tts = rtts_srv.RivaSpeechSynthesisStub(channel)
req = rtts.SynthesizeSpeechRequest()
req.text = args.text
req.language_code = "en-US" # currently required to be "en-US"
req.encoding = ra.AudioEncoding.LINEAR_PCM # Supports LINEAR_PCM, FLAC, MULAW and ALAW audio encodings
req.sample_rate_hz = 22050 # ignored, audio returned will be 22.05KHz
req.voice_name = "ljspeech" # ignored
resp = riva_tts.Synthesize(req)
@Tapssig
Copy link

Tapssig commented Jul 4, 2022

Capture
The module 'riva_api.riva_tts_pb2' is missing please help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment