Skip to content

Commit

Permalink
update main readmes with new web and android
Browse files Browse the repository at this point in the history
  • Loading branch information
bejager committed May 9, 2024
1 parent 579d2d2 commit fcae359
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 14 deletions.
79 changes: 71 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Orca provides a set of parameters to control the synthesized speech. The followi
| Parameter | Default | Description |
|:-----------:|:-------:|:--------------------------------------------------------------------------------------------------------------------------:|
| speech rate | 1.0 | Speed of generated speech. Valid values are within [0.7, 1.3]. <br/>Higher (lower) values generate faster (slower) speech. |
| random state| random | Sets the random state for sampling during synthesis. <br/>Valid values are all non-negative integers. <br/>If not provided, a random seed will be chosen. |

### Audio output

Expand Down Expand Up @@ -297,6 +298,8 @@ the text to be synthesized including potential [custom pronunciations](#custom-p

When done be sure to explicitly release the resources using `orca.delete()`.

For more details, see the [iOS SDK](./binding/ios/).

### C

The header file [include/pv_orca.h](./include/pv_orca.h) contains relevant information on Orca's C SDK.
Expand Down Expand Up @@ -455,12 +458,48 @@ const orca = await OrcaWorker.create(
"${ACCESS_KEY}",
{ base64: orcaParams }
);
```

Replace `${ACCESS_KEY}` with yours obtained from [Picovoice Console](https://console.picovoice.ai/).

#### Streaming synthesis

To synthesize a text stream, create an `OrcaStream` object and add text to it one-by-one.
Call `flush` to synthesize any remaining text, and `close` to delete the `OrcaStream` object:

```typescript
const orcaStream = await orca.streamOpen();

function* textStream(): IterableIterator<string> {
... // yield text chunks e.g. from an LLM response
}

for (const textChunk of textStream()) {
const pcm = await orcaStream.synthesize(textChunk);
if (pcm !== null) {
// handle pcm
}
}

const flushedPcm = orcaStream.flush();
if (flushedPcm !== null) {
// handle pcm
}

const speechPcm = await orca.synthesize("${TEXT}")
orcaStream.close();
```

#### Single synthesis

```typescript
const { speechPcm, alignments } = await orca.synthesize("${TEXT}")
```

Replace `${ACCESS_KEY}` with yours obtained from [Picovoice Console](https://console.picovoice.ai/). Finally, when done
release the resources using `orca.release()`.
#### Release resources

Finally, when done release the resources using `orca.release()`.

For more details, see the [Web SDK](./binding/web/).

### Android

Expand All @@ -485,18 +524,42 @@ try {
.setAccessKey(accessKey)
.setModelPath(modelPath)
.build(appContext);

short[] pcm = orca.synthesize(
"${TEXT}",
new OrcaSynthesizeParams.Builder().build());

} catch (OrcaException ex) { }
```

Replace `${ACCESS_KEY}` with yours obtained from Picovoice Console, `${MODEL_FILE_PATH}` with an
Orca [voice model file](./lib/common) and `${TEXT}` with the text to be synthesized including
potential [custom pronunciations](#custom-pronunciations).

#### Streaming synthesis

To synthesize a text stream, create an `OrcaStream` object and add text to it one-by-one.
Call `flush` to synthesize any remaining text, and `close` to delete the `OrcaStream` object:

```java
Orca.OrcaStream orcaStream = orca.streamOpen(new OrcaSynthesizeParams.Builder().build());

for (String textChunk : textGenerator()) {
short[] pcm = orcaStream.synthesize(textChunk);
if (pcm != null) {
// handle pcm
}
}

short[] flushedPcm = orcaStream.flush();
if (flushedPcm != null) {
// handle pcm
}
```

#### Single synthesis

```java
OrcaAudio audio = orca.synthesize(
"${TEXT}",
new OrcaSynthesizeParams.Builder().build());
```

Finally, when done make sure to explicitly release the resources:

```java
Expand Down
11 changes: 5 additions & 6 deletions binding/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,19 @@ const orcaStream = await orca.streamOpen();
Then, call `synthesize` on `orcaStream` to generate speech from a stream of text:

```typescript
function getNextTextChunk(): string {
... // function to get the next text chunk
function* textStream(): IterableIterator<string> {
... // yield text chunks e.g. from an LLM response
}

for (;;) {
const pcm = await orcaStream.synthesize(getNextTextChunk());
for (const textChunk of textStream()) {
const pcm = await orcaStream.synthesize(textChunk);
if (pcm !== null) {
// handle pcm
}
// break at end of text stream
}
```

`orcaStream` buffers input text until there is enough to generate audio. If there is not enough text to generate
The `OrcaStream` object buffers input text until there is enough to generate audio. If there is not enough text to generate
audio, `null` is returned.

When done, call `flush` to synthesize any remaining text, and `close` to delete the `orcaStream` object.
Expand Down

0 comments on commit fcae359

Please sign in to comment.