Skip to content

Commit

Permalink
📝 docs: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Nov 17, 2023
1 parent 47b7aeb commit 0679c9b
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 1 deletion.
91 changes: 91 additions & 0 deletions docs/api/edge-speech-tts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
group: TTS
title: EdgeSpeechTTS
apiHeader:
pkg: '@lobehub/tts'
---

`EdgeSpeechTTS` is a class for text-to-speech conversion based on Edge Speech Service.

This class supports converting text to speech and provides a set of methods to retrieve voice options and create speech synthesis requests.

```ts
constructor(options: EdgeSpeechAPI & { locale?: string }): EdgeSpeechTTS
```

## Parameters

- `options`: Object, optional.
- `serviceUrl`: String, specifies the URL of the Edge Speech Service. If provided, requests will be sent to this URL.
- `locale`: String, specifies the voice locale to use. If provided, it will be used to filter the available voice list.

## Examples

```js
// index.js
import { EdgeSpeechTTS } from '@lobehub/tts';
import { Buffer } from 'buffer';
import fs from 'fs';
import path from 'path';

// Instantiate EdgeSpeechTTS
const tts = new EdgeSpeechTTS({ locale: 'en-US' });

// Create speech synthesis request payload
const payload = {
input: 'This is a speech demonstration',
options: {
voice: 'en-US-GuyNeural',
},
};

const speechFile = path.resolve('./speech.mp3');

// Call create method to synthesize speech
const response = await tts.create(payload);
const mp3Buffer = Buffer.from(await response.arrayBuffer());

fs.writeFileSync(speechFile, mp3Buffer);
```

Run with Bun:

```shell
$ bun index.js
```

Run in Node.js:

As the Node.js environment lacks the `WebSocket` instance, we need to polyfill WebSocket. This can be done by importing the ws package.

```js
// Import at the top of the file
import WebSocket from 'ws';

global.WebSocket = WebSocket;
```

## Static Properties

- `localeOptions`: Get all supported voice locale options.
- `voiceList`: List of all available voices.
- `voiceName`: Object containing all voice names.
- `createRequest`: Static method used to create speech synthesis requests.

## Methods

### `voiceOptions`

Get the voice options for the current instance, based on the `locale` specified during instantiation. Returns an object containing the currently available voice options.

### `createAudio(payload: EdgeSpeechPayload): Promise<AudioBuffer>`

Create speech synthesis using the given request payload.

#### Parameters

- `payload`: `EdgeSpeechPayload` type, containing the necessary information for the speech synthesis request.

#### Return Value

Returns a `Promise` that resolves to an `AudioBuffer` object containing the synthesized audio data.
11 changes: 10 additions & 1 deletion docs/api/index.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# API Reference
---
title: API Reference
nav:
title: API
order: 10
---

# API 参考指南

## TTS

- [EdgeSpeechTTS](./edge-speech-tts.zh-CN.md)
- [MicrosoftSpeechTTS](microsoft-speech-tts.zh-CN.md)
- [OpenaiTTS](openai-tts.zh-CN.md)
103 changes: 103 additions & 0 deletions docs/api/microsoft-speech-tts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
group: TTS
title: MicrosoftSpeechTTS
apiHeader:
pkg: '@lobehub/tts'
---

`MicrosoftSpeechTTS` is a class for text-to-speech using Microsoft Speech Services.

This class supports converting text to speech and provides a series of methods to retrieve speech options and create speech synthesis requests.

```ts
constructor(options: MicrosoftSpeechAPI & { locale?: string }): MicrosoftSpeechTTS
```

## Parameters

- `options`: Object, optional.
- `backendUrl`: String, specifies the URL of Microsoft Speech Services. If provided, requests will be sent to this URL.
- `locale`: String, specifies the language region to use. If provided, it will be used to filter the available voices.

## Examples

```js
// index.js
// index.js
import { MicrosoftSpeechTTS } from '@lobehub/tts';

// get MicrosoftSpeechTTS instance
const tts = new MicrosoftSpeechTTS({ locale: 'zh-CN' });

// create payload
const payload: MicrosoftSpeechPayload = {
input: 'this is a message',
options: {
voice: 'en-US-JacobNeural',
style: 'embarrassed',
},
};

const speechFile = path.resolve('./speech.mp3');

// create speech
const response = await tts.create(payload);
const mp3Buffer = Buffer.from(await response.arrayBuffer());

fs.writeFileSync(speechFile, mp3Buffer);
```

Run with Bun:

```shell
$ bun index.js
```

Run in Node.js:

Due to the lack of `WebSocket` instance in Nodejs environment, we need to polyfill WebSocket. By importing the ws package.

```js
// import at the top of the file
import WebSocket from 'ws';

global.WebSocket = WebSocket;
```

## Static Properties

- `localeOptions`: Get all supported language region options.
- `voiceList`: List of all available voices.
- `voiceName`: Object containing all voice names.
- `styleList`: List of all available voice styles.
- `createRequest`: Static method for creating speech synthesis requests.

## Methods

### `voiceOptions`

Get the voice options for the current instance, based on the `locale` specified during instantiation. Returns an object containing the current available voice options.

### `create(payload: MicrosoftSpeechPayload): Promise<Response>`

Create speech synthesis using the given request payload.

#### Parameters

- `payload`: `MicrosoftSpeechPayload` type, containing the necessary information for the speech synthesis request.

#### Return Value

Returns a `Promise` that resolves to a `Response` object containing the synthesized speech data.

### `createAudio(payload: MicrosoftSpeechPayload): Promise<AudioBuffer>`

Create speech synthesis using the given request payload and convert it to an `AudioBuffer` object.

#### Parameters

- `payload`: `MicrosoftSpeechPayload` type, containing the necessary information for the speech synthesis request.

#### Return Value

Returns a `Promise` that resolves to an `AudioBuffer` object containing the synthesized audio data.
88 changes: 88 additions & 0 deletions docs/api/openai-tts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
group: TTS
title: OpenAITTS
apiHeader:
pkg: '@lobehub/tts'
---

`OpenAITTS` is a class for text-to-speech using the OpenAI voice service.

This class supports converting text into speech and provides a set of methods for getting voice options and creating speech synthesis requests.

```ts
constructor(options: OpenAITTSAPI): OpenAITTS
```

## Parameters

- `options`: Object, optional.
- `OPENAI_PROXY_URL`: String, specifies the OpenAI proxy URL. If provided, requests will be sent to this URL.
- `OPENAI_API_KEY`: String, specifies the OpenAI API key. If provided, it will be used for authentication.
- `serviceUrl`: String, specifies the URL of the OpenAI voice service to use. If provided, it will be used for sending requests.

## Examples

```js
// index.js
import { OpenAITTS } from '@lobehub/tts';
import { Buffer } from 'buffer';
import fs from 'fs';
import path from 'path';

// Instantiate OpenAITTS
const tts = new OpenAITTS({ OPENAI_API_KEY: 'your-api-key' });

// Create speech synthesis request payload
const payload = {
input: 'This is a voice synthesis demo',
options: {
model: 'tts-1',
voice: 'alloy',
},
};

const speechFile = path.resolve('./speech.mp3');

// Call create method to synthesize speech
const response = await tts.create(payload);
const mp3Buffer = Buffer.from(await response.arrayBuffer());

fs.writeFileSync(speechFile, mp3Buffer);
```

Run with Bun:

```shell
$ bun index.js
```

In Node.js:

```js
// Import at the top of the file
import WebSocket from 'ws';

global.WebSocket = WebSocket;
```

## Static Properties

- `voiceList`: A list of all available voices.

## Methods

### `voiceOptions`

Get the voice options for the current instance based on the `serviceUrl` specified during instantiation. Returns an object containing the current available voice options.

### `createAudio(payload: OpenAITTSPayload): Promise<AudioBuffer>`

Create speech synthesis using the given request payload.

#### Parameters

- `payload`: `OpenAITTSPayload` type, contains the necessary information for the speech synthesis request.

#### Returns

Returns a `Promise` that resolves to an `AudioBuffer` object containing the synthesized audio data.
11 changes: 11 additions & 0 deletions src/react/AudioPlayer/index.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: AudioPlayer
group: UI
nav: 组件
apiHeader:
pkg: '@lobehub/tts/react'
---

## defualt

<code src="./demos/index.tsx" nopadding></code>
11 changes: 11 additions & 0 deletions src/react/AudioVisualizer/index.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: AudioVisualizer
group: UI
nav: 组件
apiHeader:
pkg: '@lobehub/tts/react'
---

## defualt

<code src="./demos/index.tsx" nopadding></code>

0 comments on commit 0679c9b

Please sign in to comment.