Skip to content

Commit

Permalink
Add simple API
Browse files Browse the repository at this point in the history
  • Loading branch information
fakerybakery committed Jan 10, 2025
1 parent 2481417 commit a8caaef
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ Install the latest release from PyPI:
pip install simpletts
```

## Quick Start
## Quick Start (Simple API)

If you don't plan on choosing a custom model or using voice cloning, you can use the simple API. Currently, the simple API uses the Kokoro model.

```python
from simpletts import tts

tts("Hello, world!").save("output.wav")
```

## Python API

**Get started with the XTTS model:**

```python
import soundfile as sf
Expand Down
31 changes: 31 additions & 0 deletions docs/simple.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Simple API

The Simple API provides an easy way to get started with SimpleTTS without worrying about model selection or configuration. It uses the Kokoro model by default.

## Usage

Import the `tts` function:

```python
from simpletts import tts
```

Generate and save audio:

```python
tts("Hello world!").save("output.wav")
```

That's all you need! The Simple API handles all the model initialization and configuration behind the scenes.

## Example

Here's a complete example showing natural text-to-speech generation:

```python
from simpletts import tts

tts("Enter your text. Supports longform synthesis.").save("output.wav")
```

The Simple API is great for basic use cases where you just want to convert text to speech without any special configuration. For more advanced usage like voice cloning or using different models, check out the [Models](models.md) documentation.
Binary file removed output.wav
Binary file not shown.
3 changes: 3 additions & 0 deletions sample/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from simpletts import tts

tts("This is a super simple T-T-S example! With just two lines of code, you can use Simple T-T-S to generate natural-sounding speech from text. By default, Simple T-T-S's simple A-P-I uses the Kokoro model.").save("output.wav")
3 changes: 3 additions & 0 deletions simpletts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def tts(text: str, **kwargs):
from simpletts.simple import simpletts
return simpletts(text, **kwargs)
18 changes: 18 additions & 0 deletions simpletts/simple/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Kokoro

from simpletts.models.kokoro import Kokoro
model = Kokoro(device="auto")

def simpletts(text: str, **kwargs):
audio, sr = model.longform(text, ref="af", **kwargs)

class AudioData:
def __init__(self, audio, sr):
self.audio = audio
self.sr = sr

def save(self, path):
import soundfile as sf
sf.write(path, self.audio, self.sr)

return AudioData(audio, sr)

0 comments on commit a8caaef

Please sign in to comment.