|
1 | | -from typing import Any, Dict, List, cast, Union, Optional, overload |
2 | | -from typing_extensions import NotRequired, TypedDict |
3 | | -from .request import Request, RequestConfig |
4 | | -from .async_request import AsyncRequest, AsyncRequestConfig |
| 1 | +from typing import Any, Dict, List, Optional, Union, cast, overload |
| 2 | + |
| 3 | +from typing_extensions import Literal, NotRequired, TypedDict |
| 4 | + |
5 | 5 | from ._config import ClientConfig |
6 | | -from typing import Any, Dict, List, cast |
7 | | -from typing_extensions import NotRequired, TypedDict, Literal |
8 | | -from .custom_typing import SupportedAccents |
9 | | -from .helpers import build_path |
10 | 6 | from ._types import BaseResponse |
| 7 | +from .async_request import AsyncRequest, AsyncRequestConfig |
| 8 | +from .request import Request, RequestConfig |
11 | 9 |
|
12 | 10 |
|
13 | 11 | class SpeechToTextParams(TypedDict): |
@@ -80,22 +78,21 @@ def speech_to_text( |
80 | 78 | blob: Union[SpeechToTextParams, bytes], |
81 | 79 | options: Optional[SpeechToTextParams] = None, |
82 | 80 | ) -> Union[SpeechToTextResponse, SpeechToTextWebhookResponse]: |
| 81 | + options = options or {} |
| 82 | + path = "/ai/transcribe" |
| 83 | + content_type = options.get("content_type", "application/octet-stream") |
| 84 | + headers = {"Content-Type": content_type} |
83 | 85 | if isinstance( |
84 | 86 | blob, dict |
85 | 87 | ): # If params is provided as a dict, we assume it's the first argument |
86 | 88 | resp = Request( |
87 | 89 | config=self.config, |
88 | | - path="/ai/transcribe", |
| 90 | + path=path, |
89 | 91 | params=cast(Dict[Any, Any], blob), |
90 | 92 | verb="post", |
91 | 93 | ).perform_with_content() |
92 | 94 | return resp |
93 | 95 |
|
94 | | - options = options or {} |
95 | | - path = build_path(base_path="/ai/transcribe", params=options) |
96 | | - content_type = options.get("content_type", "application/octet-stream") |
97 | | - headers = {"Content-Type": content_type} |
98 | | - |
99 | 96 | resp = Request( |
100 | 97 | config=self.config, |
101 | 98 | path=path, |
@@ -137,20 +134,19 @@ async def speech_to_text( |
137 | 134 | blob: Union[SpeechToTextParams, bytes], |
138 | 135 | options: Optional[SpeechToTextParams] = None, |
139 | 136 | ) -> Union[SpeechToTextResponse, SpeechToTextWebhookResponse]: |
| 137 | + options = options or {} |
| 138 | + path = "/ai/transcribe" |
| 139 | + content_type = options.get("content_type", "application/octet-stream") |
| 140 | + headers = {"Content-Type": content_type} |
140 | 141 | if isinstance(blob, dict): |
141 | 142 | resp = await AsyncRequest( |
142 | 143 | config=self.config, |
143 | | - path="/ai/transcribe", |
| 144 | + path=path, |
144 | 145 | params=cast(Dict[Any, Any], blob), |
145 | 146 | verb="post", |
146 | 147 | ).perform_with_content() |
147 | 148 | return resp |
148 | 149 |
|
149 | | - options = options or {} |
150 | | - path = build_path(base_path="/ai/transcribe", params=options) |
151 | | - content_type = options.get("content_type", "application/octet-stream") |
152 | | - headers = {"Content-Type": content_type} |
153 | | - |
154 | 150 | resp = await AsyncRequest( |
155 | 151 | config=self.config, |
156 | 152 | path=path, |
|
0 commit comments