The official Python SDK for SpeechCortex ASR platform.
Project description
SpeechCortex Python SDK
Official Python SDK for SpeechCortex ASR (Automatic Speech Recognition) platform.
Features
- Real-time Speech Recognition: WebSocket-based streaming ASR
- Batch/Post-Call Transcription: REST API for batch processing with file upload or presigned URLs
- Easy Integration: Simple, intuitive API
- Async Support: Full async/await support for modern Python applications
Requirements
- Python 3.10 or higher
Installation
pip install "git+https://github.com/speechcortex/speechcortex-sdk.git@package_init"
export SPEECHCORTEX_API_KEY=your_api_key_here
export SPEECHCORTEX_HOST=wss://api.speechcortex.com
Quick Start
Real-time Transcription
from speechcortex import SpeechCortexClient, LiveTranscriptionEvents, LiveOptions
# Initialize the client
speechcortex = SpeechCortexClient(api_key="your_api_key_here")
# Get WebSocket connection
connection = speechcortex.listen.websocket.v("1")
# Set up event handlers
def on_message(self, result, **kwargs):
sentence = result.channel.alternatives[0].transcript
if result.is_final:
print(f"Final: {sentence}")
else:
print(f"Interim: {sentence}")
def on_error(self, error, **kwargs):
print(f"Error: {error}")
# Register event handlers
connection.on(LiveTranscriptionEvents.Transcript, on_message)
connection.on(LiveTranscriptionEvents.Error, on_error)
# Configure options
options = LiveOptions(
model="zeus-v1",
language="en-US",
smart_format=True,
)
# Start the connection
connection.start(options)
# Send audio data
connection.send(audio_data)
# Close when done
connection.finish()
Using with Microphone
from speechcortex import SpeechCortexClient, LiveTranscriptionEvents, LiveOptions, Microphone
speechcortex = SpeechCortexClient()
connection = speechcortex.listen.websocket.v("1")
# Set up event handlers...
connection.on(LiveTranscriptionEvents.Transcript, on_message)
# Start connection
options = LiveOptions(model="zeus-v1", smart_format=True)
connection.start(options)
# Use microphone helper
microphone = Microphone(connection.send)
microphone.start()
# Microphone will stream audio automatically
# Press Ctrl+C to stop
microphone.finish()
connection.finish()
Batch/Post-Call Transcription
import asyncio
from speechcortex import SpeechCortexClient, BatchOptions, TranscriptionConfig
async def main():
client = SpeechCortexClient(api_key="your_api_key_here")
batch = client.transcribe.batch()
async with batch:
# Method 1: Submit with presigned URL
job = await batch.submit_job(
presigned_url="https://your-bucket.s3.amazonaws.com/audio.mp3?X-Amz-Algorithm=...",
language="en-US",
model="batch-zeus",
diarize=True,
punctuate=True,
)
# Wait for completion
result = await batch.wait_for_completion(job.job_id, timeout=300.0)
print(result.transcription)
# Method 2: Upload file directly
job = await batch.submit_job(
audio_file="path/to/audio.mp3",
language="en-US",
)
# Method 3: Convenience method (submit + wait in one call)
result = await batch.transcribe(
presigned_url="https://example.com/audio.mp3",
language="en-US",
timeout=300.0,
)
print(result.transcription)
asyncio.run(main())
Batch Transcription with Configuration
import asyncio
from speechcortex import SpeechCortexClient, BatchOptions, TranscriptionConfig
async def main():
client = SpeechCortexClient()
batch = client.transcribe.batch()
async with batch:
# Create transcription config
config = TranscriptionConfig(
language="en-US",
model="batch-zeus",
diarize=True,
punctuate=True,
smart_format=True,
channel=2,
)
# Create batch options
options = BatchOptions(
polling_interval=5.0,
timeout=600.0,
)
# Submit job
job = await batch.submit_job(
presigned_url="https://example.com/audio.mp3",
config=config,
)
# Wait with custom options
result = await batch.wait_for_completion(job.job_id, options=options)
asyncio.run(main())
Manual Status Polling
import asyncio
from speechcortex import SpeechCortexClient
async def main():
client = SpeechCortexClient()
batch = client.transcribe.batch()
async with batch:
# Submit job
job = await batch.submit_job(
presigned_url="https://example.com/audio.mp3",
language="en-US",
)
# Manually poll for status
while True:
status = await batch.get_status(job.job_id)
print(f"Status: {status.status}")
if status.status.upper() == "COMPLETED":
result = await batch.get_transcription(job.job_id)
print(result.transcription)
break
elif status.status.upper() == "FAILED":
print(f"Job failed: {status.error_message}")
break
await asyncio.sleep(3)
asyncio.run(main())
Configuration
API Key
Set your API key via environment variable:
export SPEECHCORTEX_API_KEY=your_api_key_here
Or pass it directly:
speechcortex = SpeechCortexClient(api_key="your_api_key_here")
Custom Endpoints
from speechcortex import SpeechCortexClient, SpeechCortexClientOptions
config = SpeechCortexClientOptions(
api_key="your_api_key",
url="https://custom-api.speechcortex.com"
)
speechcortex = SpeechCortexClient(config=config)
Features
Real-time Transcription Options
model: ASR model to use (e.g., "zeus-v1")language: Language code (e.g., "en-US")smart_format: Enable smart formattingpunctuate: Enable punctuationinterim_results: Receive interim resultsutterance_end_ms: Utterance end timeout in millisecondsvad_events: Enable voice activity detection events
Batch Transcription Options
language: Language code (e.g., "en-US", "ENGLISH")model: Transcription model (default: "batch-zeus")diarize: Enable speaker diarization (default: False)punctuate: Enable punctuation (default: True)smart_format: Enable smart formatting (default: True)channel: Number of audio channels (default: 2)polling_interval: Time between status checks in seconds (default: 3.0)timeout: Maximum time to wait for completion in seconds (default: None)
Events
Open: Connection openedTranscript: Transcription result receivedMetadata: Metadata receivedSpeechStarted: Speech detectedUtteranceEnd: End of utterance detectedClose: Connection closedError: Error occurredUnhandled: Unhandled message received
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/speechcortex/speechcortex-sdk.git
cd speechcortex-sdk
# Install dependencies
pip install -r requirements-dev.txt
# Run tests
pytest
# Run linting
pylint speechcortex/
# Format code
black speechcortex/
License
MIT License - see LICENSE file for details.
Support
For issues, questions, or contributions, please visit our GitHub repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file speechcortex_sdk-0.1.4.tar.gz.
File metadata
- Download URL: speechcortex_sdk-0.1.4.tar.gz
- Upload date:
- Size: 29.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
123152209706bf36fd3894f8390d20e25186e48a339329c073171eb1d84aefed
|
|
| MD5 |
16fbacf1e16fb8b52d77b27431a4a47d
|
|
| BLAKE2b-256 |
d88f9549c89370fe5fd404c203c8879f12d1f5b753629d2e6a706d9f9c285282
|
Provenance
The following attestation bundles were made for speechcortex_sdk-0.1.4.tar.gz:
Publisher:
publish.yml on speechcortex/speechcortex-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
speechcortex_sdk-0.1.4.tar.gz -
Subject digest:
123152209706bf36fd3894f8390d20e25186e48a339329c073171eb1d84aefed - Sigstore transparency entry: 1271910883
- Sigstore integration time:
-
Permalink:
speechcortex/speechcortex-sdk@0281c04b428d4befd9b06a05c261736c87007acc -
Branch / Tag:
refs/heads/turn_detection_and_speech_filter - Owner: https://github.com/speechcortex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0281c04b428d4befd9b06a05c261736c87007acc -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file speechcortex_sdk-0.1.4-py3-none-any.whl.
File metadata
- Download URL: speechcortex_sdk-0.1.4-py3-none-any.whl
- Upload date:
- Size: 35.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f327c365eeb130ae4b4fd4dfea4bebeaeecae5f3cd37c3e8e47969f54680bec
|
|
| MD5 |
29d9aeefbf679008ab6cea3f31679d38
|
|
| BLAKE2b-256 |
fba9b792671f4ae1507a6c4a6826d758de918b1531aa9f2753f5fa2058e92cb3
|
Provenance
The following attestation bundles were made for speechcortex_sdk-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on speechcortex/speechcortex-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
speechcortex_sdk-0.1.4-py3-none-any.whl -
Subject digest:
4f327c365eeb130ae4b4fd4dfea4bebeaeecae5f3cd37c3e8e47969f54680bec - Sigstore transparency entry: 1271910903
- Sigstore integration time:
-
Permalink:
speechcortex/speechcortex-sdk@0281c04b428d4befd9b06a05c261736c87007acc -
Branch / Tag:
refs/heads/turn_detection_and_speech_filter - Owner: https://github.com/speechcortex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0281c04b428d4befd9b06a05c261736c87007acc -
Trigger Event:
workflow_dispatch
-
Statement type: