Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for saving audio files #897

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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