-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
136 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from marvin.components.ai_classifier import ai_classifier as classifier | ||
from marvin.components.ai_function import ai_fn as fn | ||
from marvin.components.ai_image import create_image as image | ||
from marvin.components.ai_model import ai_model as model | ||
from marvin.components.speech import speak | ||
|
||
__all__ = ["speak", "fn", "model", "image", "classifier"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from pathlib import Path | ||
from typing import ( | ||
TYPE_CHECKING, | ||
Any, | ||
Callable, | ||
Coroutine, | ||
Literal, | ||
Optional, | ||
TypeVar, | ||
) | ||
|
||
from typing_extensions import ParamSpec | ||
|
||
if TYPE_CHECKING: | ||
from openai._base_client import HttpxBinaryResponseContent | ||
|
||
T = TypeVar("T") | ||
|
||
P = ParamSpec("P") | ||
|
||
|
||
def speak( | ||
input: str, | ||
*, | ||
create: Optional[Callable[..., "HttpxBinaryResponseContent"]] = None, | ||
model: Optional[str] = "tts-1-hd", | ||
voice: Optional[ | ||
Literal["alloy", "echo", "fable", "onyx", "nova", "shimmer"] | ||
] = None, | ||
response_format: Optional[Literal["mp3", "opus", "aac", "flac"]] = None, | ||
speed: Optional[float] = None, | ||
filepath: Path, | ||
) -> None: | ||
if create is None: | ||
from marvin.settings import settings | ||
|
||
create = settings.openai.audio.speech.create | ||
return create( | ||
input=input, | ||
**({"model": model} if model else {}), | ||
**({"voice": voice} if voice else {}), | ||
**({"response_format": response_format} if response_format else {}), | ||
**({"speed": speed} if speed else {}), | ||
).stream_to_file(filepath) | ||
|
||
|
||
async def aspeak( | ||
input: str, | ||
*, | ||
acreate: Optional[ | ||
Callable[..., Coroutine[Any, Any, "HttpxBinaryResponseContent"]] | ||
] = None, | ||
model: Optional[str], | ||
voice: Optional[ | ||
Literal["alloy", "echo", "fable", "onyx", "nova", "shimmer"] | ||
] = None, | ||
response_format: Optional[Literal["mp3", "opus", "aac", "flac"]] = None, | ||
speed: Optional[float] = None, | ||
filepath: Path, | ||
) -> None: | ||
if acreate is None: | ||
from marvin.settings import settings | ||
|
||
acreate = settings.openai.audio.speech.acreate | ||
return ( | ||
await acreate( | ||
input=input, | ||
**({"model": model} if model else {}), | ||
**({"voice": voice} if voice else {}), | ||
**({"response_format": response_format} if response_format else {}), | ||
**({"speed": speed} if speed else {}), | ||
) | ||
).stream_to_file(filepath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters