Skip to content

Commit 2ea3073

Browse files
committed
Create studio module for advanced editing features
1 parent ddbc0dd commit 2ea3073

File tree

2 files changed

+352
-0
lines changed

2 files changed

+352
-0
lines changed

src/neuralaudio/studio/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
from .types import (
4+
BodyCreatePodcastV1StudioPodcastsPostDurationScale,
5+
BodyCreatePodcastV1StudioPodcastsPostMode,
6+
BodyCreatePodcastV1StudioPodcastsPostMode_Bulletin,
7+
BodyCreatePodcastV1StudioPodcastsPostMode_Conversation,
8+
BodyCreatePodcastV1StudioPodcastsPostQualityPreset,
9+
BodyCreatePodcastV1StudioPodcastsPostSource,
10+
BodyCreatePodcastV1StudioPodcastsPostSourceItem,
11+
BodyCreatePodcastV1StudioPodcastsPostSourceItem_Text,
12+
BodyCreatePodcastV1StudioPodcastsPostSourceItem_Url,
13+
)
14+
from . import chapters, projects
15+
from .projects import (
16+
ProjectsAddRequestApplyTextNormalization,
17+
ProjectsAddRequestFiction,
18+
ProjectsAddRequestTargetAudience,
19+
)
20+
21+
__all__ = [
22+
"BodyCreatePodcastV1StudioPodcastsPostDurationScale",
23+
"BodyCreatePodcastV1StudioPodcastsPostMode",
24+
"BodyCreatePodcastV1StudioPodcastsPostMode_Bulletin",
25+
"BodyCreatePodcastV1StudioPodcastsPostMode_Conversation",
26+
"BodyCreatePodcastV1StudioPodcastsPostQualityPreset",
27+
"BodyCreatePodcastV1StudioPodcastsPostSource",
28+
"BodyCreatePodcastV1StudioPodcastsPostSourceItem",
29+
"BodyCreatePodcastV1StudioPodcastsPostSourceItem_Text",
30+
"BodyCreatePodcastV1StudioPodcastsPostSourceItem_Url",
31+
"ProjectsAddRequestApplyTextNormalization",
32+
"ProjectsAddRequestFiction",
33+
"ProjectsAddRequestTargetAudience",
34+
"chapters",
35+
"projects",
36+
]

src/neuralaudio/studio/client.py

Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,316 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
import typing
4+
from ..core.client_wrapper import SyncClientWrapper
5+
from .projects.client import ProjectsClient
6+
from .chapters.client import ChaptersClient
7+
from .types.body_create_podcast_v_1_studio_podcasts_post_mode import BodyCreatePodcastV1StudioPodcastsPostMode
8+
from .types.body_create_podcast_v_1_studio_podcasts_post_source import BodyCreatePodcastV1StudioPodcastsPostSource
9+
from .types.body_create_podcast_v_1_studio_podcasts_post_quality_preset import (
10+
BodyCreatePodcastV1StudioPodcastsPostQualityPreset,
11+
)
12+
from .types.body_create_podcast_v_1_studio_podcasts_post_duration_scale import (
13+
BodyCreatePodcastV1StudioPodcastsPostDurationScale,
14+
)
15+
from ..core.request_options import RequestOptions
16+
from ..types.podcast_project_response_model import PodcastProjectResponseModel
17+
from ..core.serialization import convert_and_respect_annotation_metadata
18+
from ..core.unchecked_base_model import construct_type
19+
from ..errors.unprocessable_entity_error import UnprocessableEntityError
20+
from ..types.http_validation_error import HttpValidationError
21+
from json.decoder import JSONDecodeError
22+
from ..core.api_error import ApiError
23+
from ..core.client_wrapper import AsyncClientWrapper
24+
from .projects.client import AsyncProjectsClient
25+
from .chapters.client import AsyncChaptersClient
26+
27+
# this is used as the default value for optional parameters
28+
OMIT = typing.cast(typing.Any, ...)
29+
30+
31+
class StudioClient:
32+
def __init__(self, *, client_wrapper: SyncClientWrapper):
33+
self._client_wrapper = client_wrapper
34+
self.projects = ProjectsClient(client_wrapper=self._client_wrapper)
35+
self.chapters = ChaptersClient(client_wrapper=self._client_wrapper)
36+
37+
def create_podcast(
38+
self,
39+
*,
40+
model_id: str,
41+
mode: BodyCreatePodcastV1StudioPodcastsPostMode,
42+
source: BodyCreatePodcastV1StudioPodcastsPostSource,
43+
quality_preset: typing.Optional[BodyCreatePodcastV1StudioPodcastsPostQualityPreset] = OMIT,
44+
duration_scale: typing.Optional[BodyCreatePodcastV1StudioPodcastsPostDurationScale] = OMIT,
45+
language: typing.Optional[str] = OMIT,
46+
highlights: typing.Optional[typing.Sequence[str]] = OMIT,
47+
callback_url: typing.Optional[str] = OMIT,
48+
request_options: typing.Optional[RequestOptions] = None,
49+
) -> PodcastProjectResponseModel:
50+
"""
51+
Create and auto-convert a podcast project. Currently, the LLM cost is covered by us but you will still be charged for the audio generation. In the future, you will be charged for both the LLM and audio generation costs.
52+
53+
Parameters
54+
----------
55+
model_id : str
56+
The ID of the model to be used for this Studio project, you can query GET /v1/models to list all available models.
57+
58+
mode : BodyCreatePodcastV1StudioPodcastsPostMode
59+
The type of podcast to generate
60+
61+
source : BodyCreatePodcastV1StudioPodcastsPostSource
62+
The source content for the Podcast.
63+
64+
quality_preset : typing.Optional[BodyCreatePodcastV1StudioPodcastsPostQualityPreset]
65+
Output quality of the generated audio. Must be one of:
66+
standard - standard output format, 128kbps with 44.1kHz sample rate.
67+
high - high quality output format, 192kbps with 44.1kHz sample rate and major improvements on our side. Using this setting increases the credit cost by 20%.
68+
ultra - ultra quality output format, 192kbps with 44.1kHz sample rate and highest improvements on our side. Using this setting increases the credit cost by 50%.
69+
ultra lossless - ultra quality output format, 705.6kbps with 44.1kHz sample rate and highest improvements on our side in a fully lossless format. Using this setting increases the credit cost by 100%.
70+
71+
72+
duration_scale : typing.Optional[BodyCreatePodcastV1StudioPodcastsPostDurationScale]
73+
Duration of the generated podcast. Must be one of:
74+
short - produces podcasts shorter than 3 minutes.
75+
default - produces podcasts roughly between 3-7 minutes.
76+
long - prodces podcasts longer than 7 minutes.
77+
78+
79+
language : typing.Optional[str]
80+
An optional language of the Studio project. Two-letter language code (ISO 639-1).
81+
82+
highlights : typing.Optional[typing.Sequence[str]]
83+
A brief summary or highlights of the Studio project's content, providing key points or themes. This should be between 10 and 70 characters.
84+
85+
callback_url : typing.Optional[str]
86+
A url that will be called by our service when the Studio project is converted. Request will contain a json blob containing the status of the conversion
87+
88+
request_options : typing.Optional[RequestOptions]
89+
Request-specific configuration.
90+
91+
Returns
92+
-------
93+
PodcastProjectResponseModel
94+
Successful Response
95+
96+
Examples
97+
--------
98+
from neuralaudio import (
99+
NeuralAudio,
100+
PodcastConversationModeData,
101+
PodcastTextSource,
102+
)
103+
from neuralaudio.studio import (
104+
BodyCreatePodcastV1StudioPodcastsPostMode_Conversation,
105+
)
106+
107+
client = NeuralAudio(
108+
api_key="YOUR_API_KEY",
109+
)
110+
client.studio.create_podcast(
111+
model_id="model_id",
112+
mode=BodyCreatePodcastV1StudioPodcastsPostMode_Conversation(
113+
conversation=PodcastConversationModeData(
114+
host_voice_id="host_voice_id",
115+
guest_voice_id="guest_voice_id",
116+
),
117+
),
118+
source=PodcastTextSource(
119+
text="text",
120+
),
121+
)
122+
"""
123+
_response = self._client_wrapper.httpx_client.request(
124+
"v1/studio/podcasts",
125+
method="POST",
126+
json={
127+
"model_id": model_id,
128+
"mode": convert_and_respect_annotation_metadata(
129+
object_=mode, annotation=BodyCreatePodcastV1StudioPodcastsPostMode, direction="write"
130+
),
131+
"source": convert_and_respect_annotation_metadata(
132+
object_=source, annotation=BodyCreatePodcastV1StudioPodcastsPostSource, direction="write"
133+
),
134+
"quality_preset": quality_preset,
135+
"duration_scale": duration_scale,
136+
"language": language,
137+
"highlights": highlights,
138+
"callback_url": callback_url,
139+
},
140+
headers={
141+
"content-type": "application/json",
142+
},
143+
request_options=request_options,
144+
omit=OMIT,
145+
)
146+
try:
147+
if 200 <= _response.status_code < 300:
148+
return typing.cast(
149+
PodcastProjectResponseModel,
150+
construct_type(
151+
type_=PodcastProjectResponseModel, # type: ignore
152+
object_=_response.json(),
153+
),
154+
)
155+
if _response.status_code == 422:
156+
raise UnprocessableEntityError(
157+
typing.cast(
158+
HttpValidationError,
159+
construct_type(
160+
type_=HttpValidationError, # type: ignore
161+
object_=_response.json(),
162+
),
163+
)
164+
)
165+
_response_json = _response.json()
166+
except JSONDecodeError:
167+
raise ApiError(status_code=_response.status_code, body=_response.text)
168+
raise ApiError(status_code=_response.status_code, body=_response_json)
169+
170+
171+
class AsyncStudioClient:
172+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
173+
self._client_wrapper = client_wrapper
174+
self.projects = AsyncProjectsClient(client_wrapper=self._client_wrapper)
175+
self.chapters = AsyncChaptersClient(client_wrapper=self._client_wrapper)
176+
177+
async def create_podcast(
178+
self,
179+
*,
180+
model_id: str,
181+
mode: BodyCreatePodcastV1StudioPodcastsPostMode,
182+
source: BodyCreatePodcastV1StudioPodcastsPostSource,
183+
quality_preset: typing.Optional[BodyCreatePodcastV1StudioPodcastsPostQualityPreset] = OMIT,
184+
duration_scale: typing.Optional[BodyCreatePodcastV1StudioPodcastsPostDurationScale] = OMIT,
185+
language: typing.Optional[str] = OMIT,
186+
highlights: typing.Optional[typing.Sequence[str]] = OMIT,
187+
callback_url: typing.Optional[str] = OMIT,
188+
request_options: typing.Optional[RequestOptions] = None,
189+
) -> PodcastProjectResponseModel:
190+
"""
191+
Create and auto-convert a podcast project. Currently, the LLM cost is covered by us but you will still be charged for the audio generation. In the future, you will be charged for both the LLM and audio generation costs.
192+
193+
Parameters
194+
----------
195+
model_id : str
196+
The ID of the model to be used for this Studio project, you can query GET /v1/models to list all available models.
197+
198+
mode : BodyCreatePodcastV1StudioPodcastsPostMode
199+
The type of podcast to generate
200+
201+
source : BodyCreatePodcastV1StudioPodcastsPostSource
202+
The source content for the Podcast.
203+
204+
quality_preset : typing.Optional[BodyCreatePodcastV1StudioPodcastsPostQualityPreset]
205+
Output quality of the generated audio. Must be one of:
206+
standard - standard output format, 128kbps with 44.1kHz sample rate.
207+
high - high quality output format, 192kbps with 44.1kHz sample rate and major improvements on our side. Using this setting increases the credit cost by 20%.
208+
ultra - ultra quality output format, 192kbps with 44.1kHz sample rate and highest improvements on our side. Using this setting increases the credit cost by 50%.
209+
ultra lossless - ultra quality output format, 705.6kbps with 44.1kHz sample rate and highest improvements on our side in a fully lossless format. Using this setting increases the credit cost by 100%.
210+
211+
212+
duration_scale : typing.Optional[BodyCreatePodcastV1StudioPodcastsPostDurationScale]
213+
Duration of the generated podcast. Must be one of:
214+
short - produces podcasts shorter than 3 minutes.
215+
default - produces podcasts roughly between 3-7 minutes.
216+
long - prodces podcasts longer than 7 minutes.
217+
218+
219+
language : typing.Optional[str]
220+
An optional language of the Studio project. Two-letter language code (ISO 639-1).
221+
222+
highlights : typing.Optional[typing.Sequence[str]]
223+
A brief summary or highlights of the Studio project's content, providing key points or themes. This should be between 10 and 70 characters.
224+
225+
callback_url : typing.Optional[str]
226+
A url that will be called by our service when the Studio project is converted. Request will contain a json blob containing the status of the conversion
227+
228+
request_options : typing.Optional[RequestOptions]
229+
Request-specific configuration.
230+
231+
Returns
232+
-------
233+
PodcastProjectResponseModel
234+
Successful Response
235+
236+
Examples
237+
--------
238+
import asyncio
239+
240+
from neuralaudio import (
241+
AsyncNeuralAudio,
242+
PodcastConversationModeData,
243+
PodcastTextSource,
244+
)
245+
from neuralaudio.studio import (
246+
BodyCreatePodcastV1StudioPodcastsPostMode_Conversation,
247+
)
248+
249+
client = AsyncNeuralAudio(
250+
api_key="YOUR_API_KEY",
251+
)
252+
253+
254+
async def main() -> None:
255+
await client.studio.create_podcast(
256+
model_id="model_id",
257+
mode=BodyCreatePodcastV1StudioPodcastsPostMode_Conversation(
258+
conversation=PodcastConversationModeData(
259+
host_voice_id="host_voice_id",
260+
guest_voice_id="guest_voice_id",
261+
),
262+
),
263+
source=PodcastTextSource(
264+
text="text",
265+
),
266+
)
267+
268+
269+
asyncio.run(main())
270+
"""
271+
_response = await self._client_wrapper.httpx_client.request(
272+
"v1/studio/podcasts",
273+
method="POST",
274+
json={
275+
"model_id": model_id,
276+
"mode": convert_and_respect_annotation_metadata(
277+
object_=mode, annotation=BodyCreatePodcastV1StudioPodcastsPostMode, direction="write"
278+
),
279+
"source": convert_and_respect_annotation_metadata(
280+
object_=source, annotation=BodyCreatePodcastV1StudioPodcastsPostSource, direction="write"
281+
),
282+
"quality_preset": quality_preset,
283+
"duration_scale": duration_scale,
284+
"language": language,
285+
"highlights": highlights,
286+
"callback_url": callback_url,
287+
},
288+
headers={
289+
"content-type": "application/json",
290+
},
291+
request_options=request_options,
292+
omit=OMIT,
293+
)
294+
try:
295+
if 200 <= _response.status_code < 300:
296+
return typing.cast(
297+
PodcastProjectResponseModel,
298+
construct_type(
299+
type_=PodcastProjectResponseModel, # type: ignore
300+
object_=_response.json(),
301+
),
302+
)
303+
if _response.status_code == 422:
304+
raise UnprocessableEntityError(
305+
typing.cast(
306+
HttpValidationError,
307+
construct_type(
308+
type_=HttpValidationError, # type: ignore
309+
object_=_response.json(),
310+
),
311+
)
312+
)
313+
_response_json = _response.json()
314+
except JSONDecodeError:
315+
raise ApiError(status_code=_response.status_code, body=_response.text)
316+
raise ApiError(status_code=_response.status_code, body=_response_json)

0 commit comments

Comments
 (0)