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.
Files changed (167) hide show
  1. camb/__init__.py +335 -0
  2. camb/audio_separation/__init__.py +4 -0
  3. camb/audio_separation/client.py +406 -0
  4. camb/audio_separation/raw_client.py +534 -0
  5. camb/client.py +717 -0
  6. camb/core/__init__.py +105 -0
  7. camb/core/api_error.py +23 -0
  8. camb/core/client_wrapper.py +113 -0
  9. camb/core/datetime_utils.py +28 -0
  10. camb/core/file.py +67 -0
  11. camb/core/force_multipart.py +18 -0
  12. camb/core/http_client.py +663 -0
  13. camb/core/http_response.py +55 -0
  14. camb/core/http_sse/__init__.py +42 -0
  15. camb/core/http_sse/_api.py +112 -0
  16. camb/core/http_sse/_decoders.py +61 -0
  17. camb/core/http_sse/_exceptions.py +7 -0
  18. camb/core/http_sse/_models.py +17 -0
  19. camb/core/jsonable_encoder.py +100 -0
  20. camb/core/pydantic_utilities.py +260 -0
  21. camb/core/query_encoder.py +58 -0
  22. camb/core/remove_none_from_dict.py +11 -0
  23. camb/core/request_options.py +35 -0
  24. camb/core/serialization.py +276 -0
  25. camb/deprecated_streaming/__init__.py +4 -0
  26. camb/deprecated_streaming/client.py +532 -0
  27. camb/deprecated_streaming/raw_client.py +639 -0
  28. camb/dictionaries/__init__.py +4 -0
  29. camb/dictionaries/client.py +785 -0
  30. camb/dictionaries/raw_client.py +1048 -0
  31. camb/dub/__init__.py +49 -0
  32. camb/dub/client.py +846 -0
  33. camb/dub/raw_client.py +1194 -0
  34. camb/dub/types/__init__.py +53 -0
  35. camb/dub/types/dubbed_output_in_alt_format_request_payload_output_format.py +8 -0
  36. camb/dub/types/get_dubbed_output_in_alt_format_dub_alt_format_run_id_language_post_response.py +9 -0
  37. camb/dub/types/get_dubbed_run_info_dub_result_run_id_get_response.py +7 -0
  38. camb/dub/types/get_dubbing_runs_results_dubbing_results_post_response_value.py +7 -0
  39. camb/environment.py +7 -0
  40. camb/errors/__init__.py +34 -0
  41. camb/errors/unprocessable_entity_error.py +11 -0
  42. camb/folders/__init__.py +4 -0
  43. camb/folders/client.py +213 -0
  44. camb/folders/raw_client.py +278 -0
  45. camb/languages/__init__.py +4 -0
  46. camb/languages/client.py +168 -0
  47. camb/languages/raw_client.py +223 -0
  48. camb/project_setup/__init__.py +4 -0
  49. camb/project_setup/client.py +537 -0
  50. camb/project_setup/raw_client.py +655 -0
  51. camb/py.typed +0 -0
  52. camb/raw_client.py +236 -0
  53. camb/story/__init__.py +37 -0
  54. camb/story/client.py +579 -0
  55. camb/story/raw_client.py +743 -0
  56. camb/story/types/__init__.py +38 -0
  57. camb/story/types/create_story_story_post_response.py +8 -0
  58. camb/story/types/setup_story_story_setup_post_response.py +8 -0
  59. camb/streaming/__init__.py +4 -0
  60. camb/streaming/client.py +645 -0
  61. camb/streaming/raw_client.py +796 -0
  62. camb/text_to_audio/__init__.py +4 -0
  63. camb/text_to_audio/client.py +469 -0
  64. camb/text_to_audio/raw_client.py +610 -0
  65. camb/text_to_speech/__init__.py +49 -0
  66. camb/text_to_speech/baseten.py +214 -0
  67. camb/text_to_speech/client.py +742 -0
  68. camb/text_to_speech/raw_client.py +995 -0
  69. camb/text_to_speech/types/__init__.py +47 -0
  70. camb/text_to_speech/types/create_stream_tts_request_payload_language.py +71 -0
  71. camb/text_to_speech/types/create_stream_tts_request_payload_speech_model.py +7 -0
  72. camb/text_to_speech/types/get_tts_results_tts_results_post_response_value.py +7 -0
  73. camb/text_to_speech/types/get_tts_run_info_tts_result_run_id_get_response.py +7 -0
  74. camb/text_to_voice/__init__.py +4 -0
  75. camb/text_to_voice/client.py +329 -0
  76. camb/text_to_voice/raw_client.py +405 -0
  77. camb/transcription/__init__.py +4 -0
  78. camb/transcription/client.py +465 -0
  79. camb/transcription/raw_client.py +587 -0
  80. camb/translated_story/__init__.py +4 -0
  81. camb/translated_story/client.py +309 -0
  82. camb/translated_story/raw_client.py +381 -0
  83. camb/translated_tts/__init__.py +4 -0
  84. camb/translated_tts/client.py +313 -0
  85. camb/translated_tts/raw_client.py +357 -0
  86. camb/translation/__init__.py +4 -0
  87. camb/translation/client.py +631 -0
  88. camb/translation/raw_client.py +787 -0
  89. camb/types/__init__.py +236 -0
  90. camb/types/add_target_language_out.py +20 -0
  91. camb/types/audio_output_type.py +5 -0
  92. camb/types/audio_stream.py +31 -0
  93. camb/types/config_stream.py +22 -0
  94. camb/types/config_stream_pipeline.py +28 -0
  95. camb/types/create_custom_voice_out.py +19 -0
  96. camb/types/create_project_setup_out.py +19 -0
  97. camb/types/create_stream_out.py +22 -0
  98. camb/types/create_stream_request_payload.py +70 -0
  99. camb/types/create_translated_tts_out.py +19 -0
  100. camb/types/create_tts_out.py +19 -0
  101. camb/types/data_stream.py +24 -0
  102. camb/types/demixing_option.py +10 -0
  103. camb/types/dictionary_term.py +21 -0
  104. camb/types/dictionary_with_terms.py +28 -0
  105. camb/types/dubbing_result.py +22 -0
  106. camb/types/exception_reasons.py +30 -0
  107. camb/types/folder.py +20 -0
  108. camb/types/formalities.py +3 -0
  109. camb/types/gender.py +3 -0
  110. camb/types/get_audio_separation_result_out.py +20 -0
  111. camb/types/get_create_project_setup_response.py +21 -0
  112. camb/types/get_probe_stream_in.py +21 -0
  113. camb/types/get_probe_stream_out.py +24 -0
  114. camb/types/get_setup_story_result_response.py +21 -0
  115. camb/types/get_text_to_voice_result_out.py +19 -0
  116. camb/types/get_tts_result_out_file_url.py +19 -0
  117. camb/types/http_validation_error.py +20 -0
  118. camb/types/language_enums.py +154 -0
  119. camb/types/language_pydantic_model.py +21 -0
  120. camb/types/languages.py +3 -0
  121. camb/types/orchestrator_pipeline_call_result.py +19 -0
  122. camb/types/orchestrator_pipeline_result.py +25 -0
  123. camb/types/orchestrator_pipeline_result_exception_reason.py +7 -0
  124. camb/types/orchestrator_pipeline_result_message.py +5 -0
  125. camb/types/output_format.py +10 -0
  126. camb/types/overdub_config.py +37 -0
  127. camb/types/project_details.py +28 -0
  128. camb/types/revoicing_option.py +5 -0
  129. camb/types/run_i_ds_request_payload.py +19 -0
  130. camb/types/segmenting_option.py +5 -0
  131. camb/types/source_stream.py +30 -0
  132. camb/types/story_details.py +27 -0
  133. camb/types/stream_category.py +3 -0
  134. camb/types/stream_tts_inference_options.py +38 -0
  135. camb/types/stream_tts_output_configuration.py +33 -0
  136. camb/types/stream_tts_voice_settings.py +28 -0
  137. camb/types/stream_type.py +3 -0
  138. camb/types/stream_url_for_languages.py +21 -0
  139. camb/types/target_stream.py +34 -0
  140. camb/types/task_status.py +5 -0
  141. camb/types/term_translation_input.py +21 -0
  142. camb/types/term_translation_output.py +20 -0
  143. camb/types/text_to_audio_result.py +19 -0
  144. camb/types/text_to_audio_type.py +5 -0
  145. camb/types/transcribing_option.py +5 -0
  146. camb/types/transcript.py +22 -0
  147. camb/types/transcript_data_type.py +5 -0
  148. camb/types/transcript_file_format.py +5 -0
  149. camb/types/transcription_result.py +20 -0
  150. camb/types/translating_option.py +5 -0
  151. camb/types/translation_result.py +19 -0
  152. camb/types/tts_provider.py +3 -0
  153. camb/types/validation_error.py +22 -0
  154. camb/types/validation_error_loc_item.py +5 -0
  155. camb/types/video_output_type_without_avi.py +5 -0
  156. camb/types/video_stream.py +28 -0
  157. camb/types/voice.py +28 -0
  158. camb/voice_cloning/__init__.py +34 -0
  159. camb/voice_cloning/client.py +265 -0
  160. camb/voice_cloning/raw_client.py +320 -0
  161. camb/voice_cloning/types/__init__.py +36 -0
  162. camb/voice_cloning/types/list_voices_list_voices_get_response_item.py +7 -0
  163. camb_sdk-1.5.4.dist-info/METADATA +282 -0
  164. camb_sdk-1.5.4.dist-info/RECORD +167 -0
  165. camb_sdk-1.5.4.dist-info/WHEEL +5 -0
  166. camb_sdk-1.5.4.dist-info/licenses/LICENSE +21 -0
  167. 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
+ )