speechmatics-batch 0.1.0__tar.gz

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.
@@ -0,0 +1,289 @@
1
+ Metadata-Version: 2.4
2
+ Name: speechmatics-batch
3
+ Version: 0.1.0
4
+ Summary: Speechmatics Batch API Client
5
+ Author-email: Speechmatics <support@speechmatics.com>
6
+ License-Expression: MIT
7
+ Project-URL: homepage, https://github.com/speechmatics/speechmatics-python-sdk
8
+ Project-URL: documentation, https://docs.speechmatics.com/
9
+ Project-URL: repository, https://github.com/speechmatics/speechmatics-python-sdk
10
+ Project-URL: issues, https://github.com/speechmatics/speechmatics-python-sdk/issues
11
+ Keywords: speechmatics,speech-to-text,batch,transcription,api
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ Requires-Dist: aiohttp
25
+ Requires-Dist: aiofiles
26
+ Provides-Extra: dev
27
+ Requires-Dist: black; extra == "dev"
28
+ Requires-Dist: ruff; extra == "dev"
29
+ Requires-Dist: mypy; extra == "dev"
30
+ Requires-Dist: types-aiofiles; extra == "dev"
31
+ Requires-Dist: pre-commit; extra == "dev"
32
+ Requires-Dist: pytest; extra == "dev"
33
+ Requires-Dist: pytest-asyncio; extra == "dev"
34
+ Requires-Dist: pytest-cov; extra == "dev"
35
+ Requires-Dist: pytest-mock; extra == "dev"
36
+ Requires-Dist: build; extra == "dev"
37
+
38
+ # Speechmatics Batch API Client
39
+
40
+ Async Python client for Speechmatics Batch API.
41
+
42
+ ## Features
43
+
44
+ - Async API client with comprehensive error handling
45
+ - Type hints throughout for better IDE support
46
+ - Environment variable support for credentials
47
+ - Easy-to-use interface for submitting, monitoring, and retrieving transcription jobs
48
+ - Full job configuration support with all Speechmatics features
49
+ - Intelligent transcript formatting with speaker diarization
50
+ - Support for multiple output formats (JSON, TXT, SRT)
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install speechmatics-batch
56
+ ```
57
+
58
+ ## Usage
59
+
60
+ ### Quick Start
61
+
62
+ ```python
63
+ import asyncio
64
+ from speechmatics.batch import AsyncClient
65
+
66
+ async def main():
67
+ # Create a client using environment variable SPEECHMATICS_API_KEY
68
+ async with AsyncClient() as client:
69
+ # Simple transcription
70
+ result = await client.transcribe("audio.wav")
71
+ print(result.transcript_text)
72
+
73
+ asyncio.run(main())
74
+ ```
75
+
76
+ ### Basic Job Workflow
77
+
78
+ ```python
79
+ import asyncio
80
+ from speechmatics.batch import AsyncClient, JobConfig, JobType, TranscriptionConfig
81
+
82
+ async def main():
83
+ # Create client with explicit API key
84
+ async with AsyncClient(api_key="your-api-key") as client:
85
+
86
+ # Configure transcription
87
+ config = JobConfig(
88
+ type=JobType.TRANSCRIPTION,
89
+ transcription_config=TranscriptionConfig(
90
+ language="en",
91
+ enable_entities=True,
92
+ diarization="speaker"
93
+ )
94
+ )
95
+
96
+ # Submit job
97
+ job = await client.submit_job("audio.wav", config=config)
98
+ print(f"Job submitted: {job.id}")
99
+
100
+ # Wait for completion
101
+ result = await client.wait_for_completion(
102
+ job.id,
103
+ polling_interval=2.0,
104
+ timeout=300.0
105
+ )
106
+
107
+ # Access results
108
+ print(f"Transcript: {result.transcript_text}")
109
+ print(f"Confidence: {result.confidence}")
110
+
111
+ asyncio.run(main())
112
+ ```
113
+
114
+ ### Advanced Configuration
115
+
116
+ ```python
117
+ import asyncio
118
+ from speechmatics.batch import (
119
+ AsyncClient,
120
+ JobConfig,
121
+ JobType,
122
+ OperatingPoint,
123
+ TranscriptionConfig,
124
+ TranslationConfig,
125
+ SummarizationConfig
126
+ )
127
+
128
+ async def main():
129
+ async with AsyncClient(api_key="your-api-key") as client:
130
+
131
+ # Advanced job configuration
132
+ config = JobConfig(
133
+ type=JobType.TRANSCRIPTION,
134
+ transcription_config=TranscriptionConfig(
135
+ language="en",
136
+ operating_point=OperatingPoint.ENHANCED,
137
+ enable_entities=True,
138
+ diarization="speaker",
139
+ ),
140
+ translation_config=TranslationConfig(target_languages=["es", "fr"]),
141
+ summarization_config=SummarizationConfig(
142
+ content_type="conversational", summary_length="brief"
143
+ ),
144
+ )
145
+
146
+ result = await client.transcribe("audio.wav", config=config)
147
+
148
+ # Access advanced features
149
+ if result.summary:
150
+ print(f"Summary: {result.summary}")
151
+ if result.translations:
152
+ print(f"Translations: {result.translations}")
153
+
154
+ asyncio.run(main())
155
+ ```
156
+
157
+ ### Manual Job Management
158
+
159
+ ```python
160
+ import asyncio
161
+ from speechmatics.batch import AsyncClient, JobStatus
162
+
163
+ async def main():
164
+ async with AsyncClient() as client:
165
+
166
+ # Submit job
167
+ job = await client.submit_job("audio.wav")
168
+
169
+ # Check job status
170
+ job_details = await client.get_job_info(job.id)
171
+ print(f"Status: {job_details.status}")
172
+
173
+ # Wait for completion manually
174
+ while job_details.status == JobStatus.RUNNING:
175
+ await asyncio.sleep(5)
176
+ job_details = await client.get_job_info(job.id)
177
+
178
+ if job_details.status == JobStatus.DONE:
179
+ # Get transcript
180
+ transcript = await client.get_transcript(job.id)
181
+ print(transcript.transcript_text)
182
+ else:
183
+ print(f"Job failed with status: {job_details.status}")
184
+
185
+ asyncio.run(main())
186
+ ```
187
+
188
+ ### Different Output Formats
189
+
190
+ ```python
191
+ import asyncio
192
+ from speechmatics.batch import AsyncClient, FormatType
193
+
194
+ async def main():
195
+ async with AsyncClient() as client:
196
+ job = await client.submit_job("audio.wav")
197
+
198
+ # Get JSON format (default)
199
+ json_result = await client.get_transcript(job.id, format_type=FormatType.JSON)
200
+ print(json_result.transcript_text)
201
+
202
+ # Get plain text
203
+ txt_result = await client.get_transcript(job.id, format_type=FormatType.TXT)
204
+ print(txt_result)
205
+
206
+ # Get SRT subtitles
207
+ srt_result = await client.get_transcript(job.id, format_type=FormatType.SRT)
208
+ print(srt_result)
209
+
210
+ asyncio.run(main())
211
+ ```
212
+
213
+ ### Error Handling
214
+
215
+ ```python
216
+ import asyncio
217
+ from speechmatics.batch import (
218
+ AsyncClient,
219
+ BatchError,
220
+ AuthenticationError,
221
+ JobError,
222
+ TimeoutError
223
+ )
224
+
225
+ async def main():
226
+ try:
227
+ async with AsyncClient() as client:
228
+ result = await client.transcribe("audio.wav", timeout=120.0)
229
+ print(result.transcript_text)
230
+
231
+ except AuthenticationError:
232
+ print("Invalid API key")
233
+ except BatchError as e:
234
+ print(f"Job submission failed: {e}")
235
+ except JobError as e:
236
+ print(f"Job processing failed: {e}")
237
+ except TimeoutError as e:
238
+ print(f"Job timed out: {e}")
239
+ except FileNotFoundError:
240
+ print("Audio file not found")
241
+
242
+ asyncio.run(main())
243
+ ```
244
+
245
+ ### Connection Configuration
246
+
247
+ ```python
248
+ import asyncio
249
+ from speechmatics.batch import AsyncClient, ConnectionConfig
250
+
251
+ async def main():
252
+ # Custom connection settings
253
+ config = ConnectionConfig(
254
+ url="https://asr.api.speechmatics.com/v2",
255
+ api_key="your-api-key",
256
+ connect_timeout=30.0,
257
+ operation_timeout=600.0
258
+ )
259
+
260
+ async with AsyncClient(conn_config=config) as client:
261
+ result = await client.transcribe("audio.wav")
262
+ print(result.transcript_text)
263
+
264
+ asyncio.run(main())
265
+ ```
266
+
267
+ ## Logging
268
+
269
+ The client supports logging with job id tracing for debugging. To increase logging verbosity, set `DEBUG` level in your example code:
270
+
271
+ ```python
272
+ import logging
273
+ import sys
274
+
275
+ logging.basicConfig(
276
+ level=logging.DEBUG,
277
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
278
+ handlers=[
279
+ logging.StreamHandler(sys.stdout)
280
+ ]
281
+ )
282
+ ```
283
+
284
+ ## Environment Variables
285
+
286
+ The client supports the following environment variables:
287
+
288
+ - `SPEECHMATICS_API_KEY`: Your Speechmatics API key
289
+ - `SPEECHMATICS_BATCH_URL`: Custom API endpoint URL (optional)
@@ -0,0 +1,252 @@
1
+ # Speechmatics Batch API Client
2
+
3
+ Async Python client for Speechmatics Batch API.
4
+
5
+ ## Features
6
+
7
+ - Async API client with comprehensive error handling
8
+ - Type hints throughout for better IDE support
9
+ - Environment variable support for credentials
10
+ - Easy-to-use interface for submitting, monitoring, and retrieving transcription jobs
11
+ - Full job configuration support with all Speechmatics features
12
+ - Intelligent transcript formatting with speaker diarization
13
+ - Support for multiple output formats (JSON, TXT, SRT)
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install speechmatics-batch
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ### Quick Start
24
+
25
+ ```python
26
+ import asyncio
27
+ from speechmatics.batch import AsyncClient
28
+
29
+ async def main():
30
+ # Create a client using environment variable SPEECHMATICS_API_KEY
31
+ async with AsyncClient() as client:
32
+ # Simple transcription
33
+ result = await client.transcribe("audio.wav")
34
+ print(result.transcript_text)
35
+
36
+ asyncio.run(main())
37
+ ```
38
+
39
+ ### Basic Job Workflow
40
+
41
+ ```python
42
+ import asyncio
43
+ from speechmatics.batch import AsyncClient, JobConfig, JobType, TranscriptionConfig
44
+
45
+ async def main():
46
+ # Create client with explicit API key
47
+ async with AsyncClient(api_key="your-api-key") as client:
48
+
49
+ # Configure transcription
50
+ config = JobConfig(
51
+ type=JobType.TRANSCRIPTION,
52
+ transcription_config=TranscriptionConfig(
53
+ language="en",
54
+ enable_entities=True,
55
+ diarization="speaker"
56
+ )
57
+ )
58
+
59
+ # Submit job
60
+ job = await client.submit_job("audio.wav", config=config)
61
+ print(f"Job submitted: {job.id}")
62
+
63
+ # Wait for completion
64
+ result = await client.wait_for_completion(
65
+ job.id,
66
+ polling_interval=2.0,
67
+ timeout=300.0
68
+ )
69
+
70
+ # Access results
71
+ print(f"Transcript: {result.transcript_text}")
72
+ print(f"Confidence: {result.confidence}")
73
+
74
+ asyncio.run(main())
75
+ ```
76
+
77
+ ### Advanced Configuration
78
+
79
+ ```python
80
+ import asyncio
81
+ from speechmatics.batch import (
82
+ AsyncClient,
83
+ JobConfig,
84
+ JobType,
85
+ OperatingPoint,
86
+ TranscriptionConfig,
87
+ TranslationConfig,
88
+ SummarizationConfig
89
+ )
90
+
91
+ async def main():
92
+ async with AsyncClient(api_key="your-api-key") as client:
93
+
94
+ # Advanced job configuration
95
+ config = JobConfig(
96
+ type=JobType.TRANSCRIPTION,
97
+ transcription_config=TranscriptionConfig(
98
+ language="en",
99
+ operating_point=OperatingPoint.ENHANCED,
100
+ enable_entities=True,
101
+ diarization="speaker",
102
+ ),
103
+ translation_config=TranslationConfig(target_languages=["es", "fr"]),
104
+ summarization_config=SummarizationConfig(
105
+ content_type="conversational", summary_length="brief"
106
+ ),
107
+ )
108
+
109
+ result = await client.transcribe("audio.wav", config=config)
110
+
111
+ # Access advanced features
112
+ if result.summary:
113
+ print(f"Summary: {result.summary}")
114
+ if result.translations:
115
+ print(f"Translations: {result.translations}")
116
+
117
+ asyncio.run(main())
118
+ ```
119
+
120
+ ### Manual Job Management
121
+
122
+ ```python
123
+ import asyncio
124
+ from speechmatics.batch import AsyncClient, JobStatus
125
+
126
+ async def main():
127
+ async with AsyncClient() as client:
128
+
129
+ # Submit job
130
+ job = await client.submit_job("audio.wav")
131
+
132
+ # Check job status
133
+ job_details = await client.get_job_info(job.id)
134
+ print(f"Status: {job_details.status}")
135
+
136
+ # Wait for completion manually
137
+ while job_details.status == JobStatus.RUNNING:
138
+ await asyncio.sleep(5)
139
+ job_details = await client.get_job_info(job.id)
140
+
141
+ if job_details.status == JobStatus.DONE:
142
+ # Get transcript
143
+ transcript = await client.get_transcript(job.id)
144
+ print(transcript.transcript_text)
145
+ else:
146
+ print(f"Job failed with status: {job_details.status}")
147
+
148
+ asyncio.run(main())
149
+ ```
150
+
151
+ ### Different Output Formats
152
+
153
+ ```python
154
+ import asyncio
155
+ from speechmatics.batch import AsyncClient, FormatType
156
+
157
+ async def main():
158
+ async with AsyncClient() as client:
159
+ job = await client.submit_job("audio.wav")
160
+
161
+ # Get JSON format (default)
162
+ json_result = await client.get_transcript(job.id, format_type=FormatType.JSON)
163
+ print(json_result.transcript_text)
164
+
165
+ # Get plain text
166
+ txt_result = await client.get_transcript(job.id, format_type=FormatType.TXT)
167
+ print(txt_result)
168
+
169
+ # Get SRT subtitles
170
+ srt_result = await client.get_transcript(job.id, format_type=FormatType.SRT)
171
+ print(srt_result)
172
+
173
+ asyncio.run(main())
174
+ ```
175
+
176
+ ### Error Handling
177
+
178
+ ```python
179
+ import asyncio
180
+ from speechmatics.batch import (
181
+ AsyncClient,
182
+ BatchError,
183
+ AuthenticationError,
184
+ JobError,
185
+ TimeoutError
186
+ )
187
+
188
+ async def main():
189
+ try:
190
+ async with AsyncClient() as client:
191
+ result = await client.transcribe("audio.wav", timeout=120.0)
192
+ print(result.transcript_text)
193
+
194
+ except AuthenticationError:
195
+ print("Invalid API key")
196
+ except BatchError as e:
197
+ print(f"Job submission failed: {e}")
198
+ except JobError as e:
199
+ print(f"Job processing failed: {e}")
200
+ except TimeoutError as e:
201
+ print(f"Job timed out: {e}")
202
+ except FileNotFoundError:
203
+ print("Audio file not found")
204
+
205
+ asyncio.run(main())
206
+ ```
207
+
208
+ ### Connection Configuration
209
+
210
+ ```python
211
+ import asyncio
212
+ from speechmatics.batch import AsyncClient, ConnectionConfig
213
+
214
+ async def main():
215
+ # Custom connection settings
216
+ config = ConnectionConfig(
217
+ url="https://asr.api.speechmatics.com/v2",
218
+ api_key="your-api-key",
219
+ connect_timeout=30.0,
220
+ operation_timeout=600.0
221
+ )
222
+
223
+ async with AsyncClient(conn_config=config) as client:
224
+ result = await client.transcribe("audio.wav")
225
+ print(result.transcript_text)
226
+
227
+ asyncio.run(main())
228
+ ```
229
+
230
+ ## Logging
231
+
232
+ The client supports logging with job id tracing for debugging. To increase logging verbosity, set `DEBUG` level in your example code:
233
+
234
+ ```python
235
+ import logging
236
+ import sys
237
+
238
+ logging.basicConfig(
239
+ level=logging.DEBUG,
240
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
241
+ handlers=[
242
+ logging.StreamHandler(sys.stdout)
243
+ ]
244
+ )
245
+ ```
246
+
247
+ ## Environment Variables
248
+
249
+ The client supports the following environment variables:
250
+
251
+ - `SPEECHMATICS_API_KEY`: Your Speechmatics API key
252
+ - `SPEECHMATICS_BATCH_URL`: Custom API endpoint URL (optional)
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "speechmatics-batch"
7
+ dynamic = ["version"]
8
+ description = "Speechmatics Batch API Client"
9
+ readme = "README.md"
10
+ authors = [{ name = "Speechmatics", email = "support@speechmatics.com" }]
11
+ license = "MIT"
12
+ requires-python = ">=3.9"
13
+ dependencies = ["aiohttp", "aiofiles"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.9",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Operating System :: OS Independent",
23
+ "Topic :: Multimedia :: Sound/Audio :: Speech",
24
+ "Topic :: Software Development :: Libraries :: Python Modules",
25
+ ]
26
+ keywords = ["speechmatics", "speech-to-text", "batch", "transcription", "api"]
27
+
28
+ [project.optional-dependencies]
29
+ dev = [
30
+ "black",
31
+ "ruff",
32
+ "mypy",
33
+ "types-aiofiles",
34
+ "pre-commit",
35
+ "pytest",
36
+ "pytest-asyncio",
37
+ "pytest-cov",
38
+ "pytest-mock",
39
+ "build",
40
+ ]
41
+
42
+ [project.urls]
43
+ homepage = "https://github.com/speechmatics/speechmatics-python-sdk"
44
+ documentation = "https://docs.speechmatics.com/"
45
+ repository = "https://github.com/speechmatics/speechmatics-python-sdk"
46
+ issues = "https://github.com/speechmatics/speechmatics-python-sdk/issues"
47
+
48
+ [tool.setuptools.dynamic]
49
+ version = { attr = "speechmatics.batch.__version__" }
50
+
51
+ [tool.setuptools.packages.find]
52
+ where = ["."]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1,47 @@
1
+ __version__ = "0.1.0"
2
+
3
+ from ._async_client import AsyncClient
4
+ from ._exceptions import AuthenticationError
5
+ from ._exceptions import BatchError
6
+ from ._exceptions import ConfigurationError
7
+ from ._exceptions import ConnectionError
8
+ from ._exceptions import JobError
9
+ from ._exceptions import TimeoutError
10
+ from ._exceptions import TransportError
11
+ from ._models import ConnectionConfig
12
+ from ._models import FormatType
13
+ from ._models import JobConfig
14
+ from ._models import JobDetails
15
+ from ._models import JobInfo
16
+ from ._models import JobStatus
17
+ from ._models import JobType
18
+ from ._models import NotificationConfig
19
+ from ._models import OperatingPoint
20
+ from ._models import SummarizationConfig
21
+ from ._models import Transcript
22
+ from ._models import TranscriptionConfig
23
+ from ._models import TranslationConfig
24
+
25
+ __all__ = [
26
+ "AsyncClient",
27
+ "ConfigurationError",
28
+ "AuthenticationError",
29
+ "ConnectionError",
30
+ "TransportError",
31
+ "BatchError",
32
+ "JobError",
33
+ "TimeoutError",
34
+ "JobConfig",
35
+ "JobDetails",
36
+ "JobInfo",
37
+ "NotificationConfig",
38
+ "OperatingPoint",
39
+ "SummarizationConfig",
40
+ "Transcript",
41
+ "TranscriptionConfig",
42
+ "TranslationConfig",
43
+ "ConnectionConfig",
44
+ "JobStatus",
45
+ "JobType",
46
+ "FormatType",
47
+ ]