Skip to content

Commit

Permalink
Fix for saving audio files
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev-Khant committed Apr 1, 2024
1 parent a38b36a commit 0607337
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
14 changes: 5 additions & 9 deletions docs/docs/audio/speech.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Marvin can generate speech from text.

!!! success "Result"
```python
audio.stream_to_file("fancy_computer.mp3")
audio.save("fancy_computer.mp3")
```
<audio controls>
<source src="/assets/audio/fancy_computer.mp3" type="audio/mpeg">
Expand All @@ -47,7 +47,7 @@ Marvin can generate speech from text.

!!! success "Result"
```python
audio.stream_to_file("hello_arthur.mp3")
audio.save("hello_arthur.mp3")
```
<audio controls>
<source src="/assets/audio/hello_arthur.mp3" type="audio/mpeg">
Expand Down Expand Up @@ -100,14 +100,10 @@ ai_say('hello')
Both `speak` and `@speech` accept a `voice` parameter that allows you to choose from a variety of voices. You can preview the available voices [here](https://platform.openai.com/docs/guides/text-to-speech/voice-options).

```python
The result of the `speak` function and `@speech` decorator is an audio stream.

## Saving audio files

The result of the `speak` function and `@speech` decorator is an audio stream. You can save this stream to disk like this:

```python
audio = marvin.speak("Hello, world!")
audio.stream_to_file("hello_world.mp3")
audio = marvin.speak("Hello, world!", voice="nova")
audio.save("hello_world.mp3") # Saving audio files
```


Expand Down
2 changes: 1 addition & 1 deletion docs/welcome/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ And remember:
import marvin

audio = marvin.speak("and above all else... don't panic!")
audio.stream_to_file("dont_panic.mp3")
audio.save("dont_panic.mp3")
```

!!! success "Result"
Expand Down
6 changes: 3 additions & 3 deletions src/marvin/ai/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import marvin
from marvin.client.openai import AsyncMarvinClient
from marvin.types import Audio, HttpxBinaryResponseContent, SpeechRequest
from marvin.types import Audio, SpeechRequest
from marvin.utilities.asyncio import run_sync
from marvin.utilities.jinja import Environment
from marvin.utilities.logging import get_logger
Expand Down Expand Up @@ -86,7 +86,7 @@ def speak(
text: str,
voice: Literal["alloy", "echo", "fable", "onyx", "nova", "shimmer"] = None,
model_kwargs: Optional[dict[str, Any]] = None,
) -> HttpxBinaryResponseContent:
) -> Audio:
"""
Generates audio from text using an AI.
Expand All @@ -101,7 +101,7 @@ def speak(
language model. Defaults to None.
Returns:
HttpxBinaryResponseContent: The generated audio.
Audio: The generated audio.
"""
return run_sync(speak_async(text, voice, model_kwargs))

Expand Down

0 comments on commit 0607337

Please sign in to comment.