camb-sdk 1.5.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- camb/__init__.py +335 -0
- camb/audio_separation/__init__.py +4 -0
- camb/audio_separation/client.py +406 -0
- camb/audio_separation/raw_client.py +534 -0
- camb/client.py +717 -0
- camb/core/__init__.py +105 -0
- camb/core/api_error.py +23 -0
- camb/core/client_wrapper.py +113 -0
- camb/core/datetime_utils.py +28 -0
- camb/core/file.py +67 -0
- camb/core/force_multipart.py +18 -0
- camb/core/http_client.py +663 -0
- camb/core/http_response.py +55 -0
- camb/core/http_sse/__init__.py +42 -0
- camb/core/http_sse/_api.py +112 -0
- camb/core/http_sse/_decoders.py +61 -0
- camb/core/http_sse/_exceptions.py +7 -0
- camb/core/http_sse/_models.py +17 -0
- camb/core/jsonable_encoder.py +100 -0
- camb/core/pydantic_utilities.py +260 -0
- camb/core/query_encoder.py +58 -0
- camb/core/remove_none_from_dict.py +11 -0
- camb/core/request_options.py +35 -0
- camb/core/serialization.py +276 -0
- camb/deprecated_streaming/__init__.py +4 -0
- camb/deprecated_streaming/client.py +532 -0
- camb/deprecated_streaming/raw_client.py +639 -0
- camb/dictionaries/__init__.py +4 -0
- camb/dictionaries/client.py +785 -0
- camb/dictionaries/raw_client.py +1048 -0
- camb/dub/__init__.py +49 -0
- camb/dub/client.py +846 -0
- camb/dub/raw_client.py +1194 -0
- camb/dub/types/__init__.py +53 -0
- camb/dub/types/dubbed_output_in_alt_format_request_payload_output_format.py +8 -0
- camb/dub/types/get_dubbed_output_in_alt_format_dub_alt_format_run_id_language_post_response.py +9 -0
- camb/dub/types/get_dubbed_run_info_dub_result_run_id_get_response.py +7 -0
- camb/dub/types/get_dubbing_runs_results_dubbing_results_post_response_value.py +7 -0
- camb/environment.py +7 -0
- camb/errors/__init__.py +34 -0
- camb/errors/unprocessable_entity_error.py +11 -0
- camb/folders/__init__.py +4 -0
- camb/folders/client.py +213 -0
- camb/folders/raw_client.py +278 -0
- camb/languages/__init__.py +4 -0
- camb/languages/client.py +168 -0
- camb/languages/raw_client.py +223 -0
- camb/project_setup/__init__.py +4 -0
- camb/project_setup/client.py +537 -0
- camb/project_setup/raw_client.py +655 -0
- camb/py.typed +0 -0
- camb/raw_client.py +236 -0
- camb/story/__init__.py +37 -0
- camb/story/client.py +579 -0
- camb/story/raw_client.py +743 -0
- camb/story/types/__init__.py +38 -0
- camb/story/types/create_story_story_post_response.py +8 -0
- camb/story/types/setup_story_story_setup_post_response.py +8 -0
- camb/streaming/__init__.py +4 -0
- camb/streaming/client.py +645 -0
- camb/streaming/raw_client.py +796 -0
- camb/text_to_audio/__init__.py +4 -0
- camb/text_to_audio/client.py +469 -0
- camb/text_to_audio/raw_client.py +610 -0
- camb/text_to_speech/__init__.py +49 -0
- camb/text_to_speech/baseten.py +214 -0
- camb/text_to_speech/client.py +742 -0
- camb/text_to_speech/raw_client.py +995 -0
- camb/text_to_speech/types/__init__.py +47 -0
- camb/text_to_speech/types/create_stream_tts_request_payload_language.py +71 -0
- camb/text_to_speech/types/create_stream_tts_request_payload_speech_model.py +7 -0
- camb/text_to_speech/types/get_tts_results_tts_results_post_response_value.py +7 -0
- camb/text_to_speech/types/get_tts_run_info_tts_result_run_id_get_response.py +7 -0
- camb/text_to_voice/__init__.py +4 -0
- camb/text_to_voice/client.py +329 -0
- camb/text_to_voice/raw_client.py +405 -0
- camb/transcription/__init__.py +4 -0
- camb/transcription/client.py +465 -0
- camb/transcription/raw_client.py +587 -0
- camb/translated_story/__init__.py +4 -0
- camb/translated_story/client.py +309 -0
- camb/translated_story/raw_client.py +381 -0
- camb/translated_tts/__init__.py +4 -0
- camb/translated_tts/client.py +313 -0
- camb/translated_tts/raw_client.py +357 -0
- camb/translation/__init__.py +4 -0
- camb/translation/client.py +631 -0
- camb/translation/raw_client.py +787 -0
- camb/types/__init__.py +236 -0
- camb/types/add_target_language_out.py +20 -0
- camb/types/audio_output_type.py +5 -0
- camb/types/audio_stream.py +31 -0
- camb/types/config_stream.py +22 -0
- camb/types/config_stream_pipeline.py +28 -0
- camb/types/create_custom_voice_out.py +19 -0
- camb/types/create_project_setup_out.py +19 -0
- camb/types/create_stream_out.py +22 -0
- camb/types/create_stream_request_payload.py +70 -0
- camb/types/create_translated_tts_out.py +19 -0
- camb/types/create_tts_out.py +19 -0
- camb/types/data_stream.py +24 -0
- camb/types/demixing_option.py +10 -0
- camb/types/dictionary_term.py +21 -0
- camb/types/dictionary_with_terms.py +28 -0
- camb/types/dubbing_result.py +22 -0
- camb/types/exception_reasons.py +30 -0
- camb/types/folder.py +20 -0
- camb/types/formalities.py +3 -0
- camb/types/gender.py +3 -0
- camb/types/get_audio_separation_result_out.py +20 -0
- camb/types/get_create_project_setup_response.py +21 -0
- camb/types/get_probe_stream_in.py +21 -0
- camb/types/get_probe_stream_out.py +24 -0
- camb/types/get_setup_story_result_response.py +21 -0
- camb/types/get_text_to_voice_result_out.py +19 -0
- camb/types/get_tts_result_out_file_url.py +19 -0
- camb/types/http_validation_error.py +20 -0
- camb/types/language_enums.py +154 -0
- camb/types/language_pydantic_model.py +21 -0
- camb/types/languages.py +3 -0
- camb/types/orchestrator_pipeline_call_result.py +19 -0
- camb/types/orchestrator_pipeline_result.py +25 -0
- camb/types/orchestrator_pipeline_result_exception_reason.py +7 -0
- camb/types/orchestrator_pipeline_result_message.py +5 -0
- camb/types/output_format.py +10 -0
- camb/types/overdub_config.py +37 -0
- camb/types/project_details.py +28 -0
- camb/types/revoicing_option.py +5 -0
- camb/types/run_i_ds_request_payload.py +19 -0
- camb/types/segmenting_option.py +5 -0
- camb/types/source_stream.py +30 -0
- camb/types/story_details.py +27 -0
- camb/types/stream_category.py +3 -0
- camb/types/stream_tts_inference_options.py +38 -0
- camb/types/stream_tts_output_configuration.py +33 -0
- camb/types/stream_tts_voice_settings.py +28 -0
- camb/types/stream_type.py +3 -0
- camb/types/stream_url_for_languages.py +21 -0
- camb/types/target_stream.py +34 -0
- camb/types/task_status.py +5 -0
- camb/types/term_translation_input.py +21 -0
- camb/types/term_translation_output.py +20 -0
- camb/types/text_to_audio_result.py +19 -0
- camb/types/text_to_audio_type.py +5 -0
- camb/types/transcribing_option.py +5 -0
- camb/types/transcript.py +22 -0
- camb/types/transcript_data_type.py +5 -0
- camb/types/transcript_file_format.py +5 -0
- camb/types/transcription_result.py +20 -0
- camb/types/translating_option.py +5 -0
- camb/types/translation_result.py +19 -0
- camb/types/tts_provider.py +3 -0
- camb/types/validation_error.py +22 -0
- camb/types/validation_error_loc_item.py +5 -0
- camb/types/video_output_type_without_avi.py +5 -0
- camb/types/video_stream.py +28 -0
- camb/types/voice.py +28 -0
- camb/voice_cloning/__init__.py +34 -0
- camb/voice_cloning/client.py +265 -0
- camb/voice_cloning/raw_client.py +320 -0
- camb/voice_cloning/types/__init__.py +36 -0
- camb/voice_cloning/types/list_voices_list_voices_get_response_item.py +7 -0
- camb_sdk-1.5.4.dist-info/METADATA +282 -0
- camb_sdk-1.5.4.dist-info/RECORD +167 -0
- camb_sdk-1.5.4.dist-info/WHEEL +5 -0
- camb_sdk-1.5.4.dist-info/licenses/LICENSE +21 -0
- camb_sdk-1.5.4.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import contextlib
|
|
2
|
+
import typing
|
|
3
|
+
|
|
4
|
+
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
5
|
+
from ..core.http_response import AsyncHttpResponse, HttpResponse
|
|
6
|
+
from ..core.request_options import RequestOptions
|
|
7
|
+
from ..core.serialization import convert_and_respect_annotation_metadata
|
|
8
|
+
from ..types.stream_tts_inference_options import StreamTtsInferenceOptions
|
|
9
|
+
from ..types.stream_tts_output_configuration import StreamTtsOutputConfiguration
|
|
10
|
+
from ..types.stream_tts_voice_settings import StreamTtsVoiceSettings
|
|
11
|
+
from .types.create_stream_tts_request_payload_language import CreateStreamTtsRequestPayloadLanguage
|
|
12
|
+
from .types.create_stream_tts_request_payload_speech_model import CreateStreamTtsRequestPayloadSpeechModel
|
|
13
|
+
|
|
14
|
+
OMIT = typing.cast(typing.Any, ...)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@contextlib.contextmanager
|
|
18
|
+
def baseten_tts(
|
|
19
|
+
client_wrapper: SyncClientWrapper,
|
|
20
|
+
*,
|
|
21
|
+
text: str,
|
|
22
|
+
language: CreateStreamTtsRequestPayloadLanguage,
|
|
23
|
+
voice_id: typing.Optional[int] = OMIT,
|
|
24
|
+
speech_model: typing.Optional[CreateStreamTtsRequestPayloadSpeechModel] = OMIT,
|
|
25
|
+
user_instructions: typing.Optional[str] = OMIT,
|
|
26
|
+
enhance_named_entities_pronunciation: typing.Optional[bool] = OMIT,
|
|
27
|
+
output_configuration: typing.Optional[StreamTtsOutputConfiguration] = OMIT,
|
|
28
|
+
voice_settings: typing.Optional[StreamTtsVoiceSettings] = OMIT,
|
|
29
|
+
inference_options: typing.Optional[StreamTtsInferenceOptions] = OMIT,
|
|
30
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
31
|
+
) -> typing.Iterator[HttpResponse[typing.Iterator[bytes]]]:
|
|
32
|
+
# Retrieve API key from provider_params
|
|
33
|
+
provider_params = client_wrapper.provider_params or {}
|
|
34
|
+
api_key = provider_params.get("api_key", "")
|
|
35
|
+
mars_pro_url = provider_params.get("mars_pro_url")
|
|
36
|
+
if not mars_pro_url:
|
|
37
|
+
raise ValueError("mars_pro_url is required for using Baseten as provider")
|
|
38
|
+
|
|
39
|
+
api_key_header_val = f"Api-Key {api_key}" if api_key else ""
|
|
40
|
+
|
|
41
|
+
# Construct Payload
|
|
42
|
+
# 1. Basic Fields
|
|
43
|
+
payload = {
|
|
44
|
+
"text": text,
|
|
45
|
+
"language": str(language).lower().replace("_", "-"),
|
|
46
|
+
"stream": True,
|
|
47
|
+
"output_format": "mp3", # Default
|
|
48
|
+
"apply_ner_nlp": False, # Default based on doc
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
# 2. Output Configuration
|
|
52
|
+
if output_configuration and output_configuration is not OMIT:
|
|
53
|
+
if output_configuration.format:
|
|
54
|
+
payload["output_format"] = str(output_configuration.format)
|
|
55
|
+
|
|
56
|
+
# 3. Voice Settings
|
|
57
|
+
if voice_settings and voice_settings is not OMIT:
|
|
58
|
+
if voice_settings.enhance_reference_audio_quality is not None:
|
|
59
|
+
payload["apply_ref_mpsenet"] = voice_settings.enhance_reference_audio_quality
|
|
60
|
+
if voice_settings.maintain_source_accent:
|
|
61
|
+
payload["accent_nudge"] = 0.8
|
|
62
|
+
|
|
63
|
+
# 4. Inference Options
|
|
64
|
+
if inference_options and inference_options is not OMIT:
|
|
65
|
+
if inference_options.temperature is not None:
|
|
66
|
+
payload["temperature"] = inference_options.temperature
|
|
67
|
+
if inference_options.inference_steps is not None:
|
|
68
|
+
payload["inference_steps"] = inference_options.inference_steps
|
|
69
|
+
|
|
70
|
+
if inference_options.speaker_similarity is not None:
|
|
71
|
+
# Formula from user snippet:
|
|
72
|
+
s = max(0.0, min(0.7, inference_options.speaker_similarity))
|
|
73
|
+
payload["campp_speaker_nudge"] = 1.5 * (1 - s / 0.7)
|
|
74
|
+
|
|
75
|
+
# 5. Extract additional params (reference_audio, reference_language) from request_options if present
|
|
76
|
+
# This allows passing 'reference_audio' without breaking the explicit signature for now.
|
|
77
|
+
extra_body = {}
|
|
78
|
+
if request_options and request_options.get("additional_body_parameters"):
|
|
79
|
+
extra_body = request_options.get("additional_body_parameters")
|
|
80
|
+
|
|
81
|
+
if "reference_audio" not in extra_body:
|
|
82
|
+
raise ValueError("reference_audio is required in additional_body_parameters for Baseten provider")
|
|
83
|
+
if "reference_language" not in extra_body:
|
|
84
|
+
raise ValueError("reference_language is required in additional_body_parameters for Baseten provider")
|
|
85
|
+
|
|
86
|
+
payload["reference_language"] = extra_body["reference_language"]
|
|
87
|
+
payload["audio_ref"] = extra_body["reference_audio"]
|
|
88
|
+
payload["reference_audio"] = extra_body["reference_audio"]
|
|
89
|
+
|
|
90
|
+
timeout = None
|
|
91
|
+
if request_options and request_options.get("timeout_in_seconds") is not None:
|
|
92
|
+
timeout = request_options.get("timeout_in_seconds")
|
|
93
|
+
|
|
94
|
+
# Use the raw httpx client to avoid SDK wrapper injecting unwanted headers/params
|
|
95
|
+
# that might interfere with Baseten's strict endpoint.
|
|
96
|
+
with client_wrapper.httpx_client.httpx_client.stream(
|
|
97
|
+
"POST",
|
|
98
|
+
mars_pro_url,
|
|
99
|
+
json=payload,
|
|
100
|
+
headers={
|
|
101
|
+
"Authorization": api_key_header_val,
|
|
102
|
+
"content-type": "application/json",
|
|
103
|
+
},
|
|
104
|
+
timeout=timeout
|
|
105
|
+
) as _response:
|
|
106
|
+
# Check status manually since we bypassed the wrapper's check
|
|
107
|
+
if not (200 <= _response.status_code < 300):
|
|
108
|
+
# Try to read error body
|
|
109
|
+
_response.read()
|
|
110
|
+
raise Exception(f"Baseten API Error: {_response.status_code} - {_response.text}")
|
|
111
|
+
|
|
112
|
+
yield HttpResponse(
|
|
113
|
+
response=_response,
|
|
114
|
+
data=(_chunk for _chunk in _response.iter_bytes(chunk_size=None)),
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@contextlib.asynccontextmanager
|
|
119
|
+
async def async_baseten_tts(
|
|
120
|
+
client_wrapper: AsyncClientWrapper,
|
|
121
|
+
*,
|
|
122
|
+
text: str,
|
|
123
|
+
language: CreateStreamTtsRequestPayloadLanguage,
|
|
124
|
+
voice_id: typing.Optional[int] = OMIT,
|
|
125
|
+
speech_model: typing.Optional[CreateStreamTtsRequestPayloadSpeechModel] = OMIT,
|
|
126
|
+
user_instructions: typing.Optional[str] = OMIT,
|
|
127
|
+
enhance_named_entities_pronunciation: typing.Optional[bool] = OMIT,
|
|
128
|
+
output_configuration: typing.Optional[StreamTtsOutputConfiguration] = OMIT,
|
|
129
|
+
voice_settings: typing.Optional[StreamTtsVoiceSettings] = OMIT,
|
|
130
|
+
inference_options: typing.Optional[StreamTtsInferenceOptions] = OMIT,
|
|
131
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
132
|
+
) -> typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]:
|
|
133
|
+
# Retrieve API key from provider_params
|
|
134
|
+
provider_params = client_wrapper.provider_params or {}
|
|
135
|
+
api_key = provider_params.get("api_key", "")
|
|
136
|
+
mars_pro_url = provider_params.get("mars_pro_url")
|
|
137
|
+
if not mars_pro_url:
|
|
138
|
+
raise ValueError("mars_pro_url is required for using Baseten as provider")
|
|
139
|
+
api_key_header_val = f"Api-Key {api_key}"
|
|
140
|
+
|
|
141
|
+
# Construct Payload
|
|
142
|
+
# 1. Basic Fields
|
|
143
|
+
payload = {
|
|
144
|
+
"text": text,
|
|
145
|
+
"language": str(language).lower().replace("_", "-"),
|
|
146
|
+
"stream": True,
|
|
147
|
+
"output_format": "mp3", # Default
|
|
148
|
+
"apply_ner_nlp": False, # Default based on doc
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
# 2. Output Configuration
|
|
152
|
+
if output_configuration and output_configuration is not OMIT:
|
|
153
|
+
if output_configuration.format:
|
|
154
|
+
payload["output_format"] = str(output_configuration.format)
|
|
155
|
+
|
|
156
|
+
# 3. Voice Settings
|
|
157
|
+
if voice_settings and voice_settings is not OMIT:
|
|
158
|
+
if voice_settings.enhance_reference_audio_quality is not None:
|
|
159
|
+
payload["apply_ref_mpsenet"] = voice_settings.enhance_reference_audio_quality
|
|
160
|
+
if voice_settings.maintain_source_accent:
|
|
161
|
+
payload["accent_nudge"] = 0.8
|
|
162
|
+
|
|
163
|
+
# 4. Inference Options
|
|
164
|
+
if inference_options and inference_options is not OMIT:
|
|
165
|
+
if inference_options.temperature is not None:
|
|
166
|
+
payload["temperature"] = inference_options.temperature
|
|
167
|
+
if inference_options.inference_steps is not None:
|
|
168
|
+
payload["inference_steps"] = inference_options.inference_steps
|
|
169
|
+
|
|
170
|
+
if inference_options.speaker_similarity is not None:
|
|
171
|
+
# Formula from user snippet:
|
|
172
|
+
s = max(0.0, min(0.7, inference_options.speaker_similarity))
|
|
173
|
+
payload["campp_speaker_nudge"] = 1.5 * (1 - s / 0.7)
|
|
174
|
+
|
|
175
|
+
# 5. Extract additional params (reference_audio, reference_language) from request_options
|
|
176
|
+
extra_body = {}
|
|
177
|
+
if request_options and request_options.get("additional_body_parameters"):
|
|
178
|
+
extra_body = request_options.get("additional_body_parameters")
|
|
179
|
+
|
|
180
|
+
if "reference_audio" not in extra_body:
|
|
181
|
+
raise ValueError("reference_audio is required in additional_body_parameters for Baseten provider")
|
|
182
|
+
if "reference_language" not in extra_body:
|
|
183
|
+
raise ValueError("reference_language is required in additional_body_parameters for Baseten provider")
|
|
184
|
+
|
|
185
|
+
payload["reference_language"] = extra_body["reference_language"]
|
|
186
|
+
payload["audio_ref"] = extra_body["reference_audio"]
|
|
187
|
+
payload["reference_audio"] = extra_body["reference_audio"]
|
|
188
|
+
|
|
189
|
+
timeout = None
|
|
190
|
+
if request_options and request_options.get("timeout_in_seconds") is not None:
|
|
191
|
+
timeout = request_options.get("timeout_in_seconds")
|
|
192
|
+
|
|
193
|
+
# Use the raw httpx client to avoid SDK wrapper injecting unwanted headers/params
|
|
194
|
+
# that might interfere with Baseten's strict endpoint.
|
|
195
|
+
async with client_wrapper.httpx_client.httpx_client.stream(
|
|
196
|
+
"POST",
|
|
197
|
+
mars_pro_url,
|
|
198
|
+
json=payload,
|
|
199
|
+
headers={
|
|
200
|
+
"Authorization": api_key_header_val,
|
|
201
|
+
"content-type": "application/json",
|
|
202
|
+
},
|
|
203
|
+
timeout=timeout
|
|
204
|
+
) as _response:
|
|
205
|
+
# Check status manually since we bypassed the wrapper's check
|
|
206
|
+
if not (200 <= _response.status_code < 300):
|
|
207
|
+
# Try to read error body
|
|
208
|
+
await _response.aread()
|
|
209
|
+
raise Exception(f"Baseten API Error: {_response.status_code} - {_response.text}")
|
|
210
|
+
|
|
211
|
+
yield AsyncHttpResponse(
|
|
212
|
+
response=_response,
|
|
213
|
+
data=(_chunk async for _chunk in _response.aiter_bytes(chunk_size=None)),
|
|
214
|
+
)
|