Orca Streaming Text-to-Speech
Android API
API Reference for the Android Orca SDK (orca-android)
package: ai.picovoice.orca
Orca
Class for the Orca Streaming Text-to-Speech engine.
Orca must be initialized using the Builder()
class. Resources should be cleaned when you are done using the delete()
function.
Orca.delete()
Releases resources acquired by Orca.
Orca.getMaxCharacterLimit()
Getter for the maximum number of characters that can be synthesized at once.
Returns
int
: Maximum number of characters that can be synthesized at once.
Orca.getSampleRate()
Getter for the audio sampling rate of the audio produced by Orca.
Returns
int
: Audio sampling rate of the audio produced by Orca.
Orca.getValidCharacters()
Getter for the set of characters that are accepted as input to Orca synthesize functions.
Returns
String[]
: Array of characters that are accepted as input to Orca synthesize functions.
Orca.getVersion()
Getter for version.
Returns
String
: CurrentOrca
version.
Orca.synthesize()
Generates audio from text.
Parameters
text
String : Text to be converted to audio.params
OrcaSynthesizeParams
: Global parameters for synthesized text.
Returns
OrcaAudio
: Synthesized audio and word alignment metadata.
Throws
OrcaException
: If there is an error while synthesizing audio.
Orca.synthesizeToFile()
Generates audio from text and saves it to a file.
Parameters
text
String : Text to be converted to audio.outputPath
String : Absolute path to the output audio file.params
OrcaSynthesizeParams
: Global parameters for synthesized text.
Returns
OrcaWord[]
: Array of synthesized words with their associated metadata.
Throws
OrcaException
: If there is an error while synthesizing audio to file.
Orca.streamOpen()
Opens an Orca.OrcaStream
object for streaming input text synthesis.
Parameters
params
OrcaSynthesizeParams
: Global parameters for synthesized text.
Returns
Orca.OrcaStream
: An instance ofOrca.OrcaStream
.
Throws
OrcaException
: If there is an error while opening theOrcaStream
object.
Orca.OrcaStream
Class for the Orca OrcaStream object for input text streaming synthesis.
An Orca.OrcaStream object is initialized via the Orca.streamOpen()
method
and needs to be closed with the Orca.OrcaStream.close()
method.
Orca.OrcaStream.synthesize()
Adds a chunk of text to the Orca.OrcaStream object and generates audio if enough text has been added.
This function is expected to be called multiple times with consecutive chunks of text from a text stream.
The incoming text is buffered as it arrives until there is enough context to convert a chunk of the
buffered text into audio. The caller needs to use Orca.OrcaStream.flush()
to generate the audio chunk
for the remaining text that has not yet been synthesized.
Parameters
text
String : A chunk of text (e.g. an LLM token) from a text input stream, comprised of valid characters. For details see the documentation ofOrca.synthesize()
.
Returns
short[]
: The generated audio as a sequence of 16-bit linearly-encoded integers,null
if no audio chunk has been produced.
Throws
OrcaException
: If there is an error while synthesizing audio.
Orca.OrcaStream.flush()
Generates audio for all the buffered text that was added to the Orca.OrcaStream object
via Orca.OrcaStream.synthesize()
.
Returns
short[]
: The generated audio as a sequence of 16-bit linearly-encoded integers,null
if no audio chunk has been produced.
Throws
OrcaException
: If there is an error while synthesizing audio.
Orca.OrcaStream.close()
Closes the Orca.OrcaStream object and releases resources acquired by it.
Orca.Builder
Builder for creating instance of Orca.
Orca.Builder.build()
Validates properties and creates an instance of the Orca Streaming Text-to-Speech engine.
Parameters
context
Context : The Android app context.
Returns
Orca
: An instance of Orca Streaming Text-to-Speech engine.
Throws
OrcaException
: If an error occurs while creating an instance of Orca.
Orca.Builder.setAccessKey()
Sets the AccessKey.
Parameters
accessKey
String : AccessKey obtained from Picovoice Console.
Returns
Orca.Builder
: Modified builder object.
Orca.Builder.setModelPath()
Sets the path to the model file.
Parameters
modelPath
String : Absolute path to the file containing Orca model parameters.
Returns
Orca.Builder
: Modified builder object.
OrcaSynthesizeParams
A class that exposes properties that can control the audio synthesized by Orca.
OrcaSynthesizeParams.getSpeechRate()
Getter for the speech rate (i.e. the pace of the synthesized speech).
Returns
float
: Speech rate.
OrcaSynthesizeParams.getRandomState()
Getter for the random state. (i.e. the random state used for the synthesized speech).
Returns
long
: Random state.
OrcaSynthesizeParams.Builder
Builder for creating an instance of OrcaSynthesizeParams
.
OrcaSynthesizeParams.Builder.build()
Validates properties and creates an instance of OrcaSynthesizeParams
.
Returns
OrcaSynthesizeParams
: An instance ofOrcaSynthesizeParams
.
Throws
OrcaInvalidArgumentException
: If there is an invalid parameter.
OrcaSynthesizeParams.Builder.setSpeechRate()
Sets the speech rate.
Parameters
speechRate
float : The pace of the synthesized speech. Valid values are within [0.7, 1.3].
Returns
OrcaSynthesizeParams.Builder
: Modified builder object.
OrcaSynthesizeParams.Builder.setRandomState()
Sets the random state.
Parameters
randomState
long : The random state used for the synthesized speech.
Returns
OrcaSynthesizeParams.Builder
: Modified builder object.
OrcaException
Exception thrown if an error occurs within Orca Streaming Text-to-Speech engine.
Exceptions:
OrcaAudio
Class that contains synthesis results returned from Orca.synthesize()
.
Parameters
pcm
short[] : Synthesized speech.wordArray
OrcaAudio.OrcaWord[] : Word alignment metadata.
OrcaAudio.getPcm()
Getter for the synthesized audio.
Returns
short[]
: Synthesized audio.
OrcaAudio.getWordArray()
Getter for synthesized words and their associated metadata.
Returns
OrcaAudio.OrcaWord[]
: Synthesized words and their associated metadata.
OrcaAudio.OrcaWord
Class that contains word alignment metadata returned from Orca.synthesizeToFile()
and from OrcaAudio
.
Parameters
word
String : Synthesized word.startSec
float : Start of word in seconds.endSec
float : End of word in seconds.phonemeArray
OrcaPhoneme[] : Synthesized phonemes and their associated metadata.
OrcaAudio.OrcaWord.getWord()
Getter for the synthesized word.
Returns
String
: Synthesized word.
OrcaAudio.OrcaWord.getStartSec()
Getter for the start of word in seconds.
Returns
float
: Start of word in seconds.
OrcaAudio.OrcaWord.getEndSec()
Getter for the end of word in seconds.
Returns
float
: End of word in seconds.
OrcaAudio.OrcaWord.getPhonemeArray()
Getter for synthesized phonemes and their associated metadata.
Returns
- OrcaPhoneme[]: Synthesized phonemes and their associated metadata.
OrcaAudio.OrcaWord.OrcaPhoneme
Class for storing phoneme metadata from OrcaAudio.OrcaWord
.
Parameters
phoneme
String : Synthesized phoneme.startSec
float : Start of phoneme in seconds.endSec
float : End of phoneme in seconds.
OrcaAudio.OrcaWord.OrcaPhoneme.getPhoneme()
Getter for the synthesized phoneme.
Returns
String
: Synthesized phoneme.
OrcaAudio.OrcaWord.OrcaPhoneme.getStartSec()
Getter for the start of phoneme in seconds.
Returns
float
: Start of phoneme in seconds.
OrcaAudio.OrcaWord.OrcaPhoneme.getEndSec()
Getter for the end of phoneme in seconds.
Returns
float
: End of phoneme in seconds.