Skip to main content

TalkLabs STT SDK - Speech-to-Text API compatible with Deepgram

Project description

TalkLabs STT SDK

SDK Python para TalkLabs Speech-to-Text API - Compatível com

License: MIT Python 3.9+

Features

  • REST API - Transcrição completa de arquivos
  • WebSocket Streaming - Transcrição em tempo real
  • Deepgram Compatible - API compatível com Deepgram
  • Múltiplos Modelos - Suporte a diferentes modelos de transcrição
  • Async Support - WebSocket assíncrono
  • Type Hints - Totalmente tipado

Instalação

pip install talklabs-stt

Quick Start

REST API (Síncrono)

from talklabs_stt import STTClient

client = STTClient(api_key="tlk_live_xxxxx")

result = client.transcribe_file("audio.wav")
print(result["results"]["channels"][0]["alternatives"][0]["transcript"])

WebSocket Streaming (Assíncrono)

import asyncio
from talklabs_stt import STTClient

async def main():
    client = STTClient(api_key="tlk_live_xxxxx")

    def on_transcript(data):
        transcript = data["channel"]["alternatives"][0]["transcript"]
        if data["is_final"]:
            print(transcript)

    await client.transcribe_stream(
        "audio.wav",
        on_transcript=on_transcript
    )

asyncio.run(main())

Uso Completo

Inicialização

from talklabs_stt import STTClient, TranscriptionOptions

# Cliente (sempre usa api.talklabs.com.br)
client = STTClient(api_key="tlk_live_xxxxx")

# Cliente com timeout customizado
client = STTClient(
    api_key="tlk_live_xxxxx",
    timeout=600  # 10 minutos
)

Opções de Transcrição

from talklabs_stt import TranscriptionOptions

options = TranscriptionOptions(
    model="large-v3",        # large-v3, medium, small
    language="pt",           # pt, en, es, etc.
    punctuate=True,          # Adicionar pontuação
    smart_format=True,       # Formatação inteligente
    detect_language=False,   # Detecção automática
    vad_filter=False,        # Filtro VAD
    interim_results=True     # Resultados intermediários (WebSocket)
)

result = client.transcribe_file("audio.wav", options=options)

Com kwargs diretos

result = client.transcribe_file(
    "audio.wav",
    model="large-v3",
    language="pt",
    punctuate=True,
    smart_format=True
)

API Reference

STTClient

transcribe_file(audio_path, options=None, **kwargs)

Transcreve arquivo completo via REST API.

Args:

  • audio_path (str): Caminho do arquivo de áudio
  • options (TranscriptionOptions, optional): Opções de transcrição
  • **kwargs: Parâmetros adicionais

Returns: dict - Resultado -compatible

transcribe_stream(audio_path, options=None, on_transcript=None, on_metadata=None, **kwargs)

Transcreve via WebSocket streaming (async).

Args:

  • audio_path (str): Caminho do arquivo
  • options (TranscriptionOptions, optional): Opções
  • on_transcript (callable, optional): Callback para transcrições
  • on_metadata (callable, optional): Callback para metadata
  • **kwargs: Parâmetros adicionais

list_models()

Lista modelos disponíveis.

Returns: dict - Lista de modelos disponíveis

Migração do Deepgram

O SDK é 100% compatível com Deepgram. Para migrar:

# Deepgram
from deepgram import DeepgramClient
dg = DeepgramClient(api_key)

# TalkLabs
from talklabs_stt import STTClient
client = STTClient(api_key)

# Mesma interface!
result = client.transcribe_file("audio.wav", language="pt")

Exemplos

Ver pasta examples/:

  • transcribe_simple.py - REST API básico
  • transcribe_stream.py - WebSocket streaming
  • list_models.py - Listar modelos
  • quick_start.py - Exemplo rápido de uso

Desenvolvimento

Benchmark de Modelos

O projeto inclui um script de benchmark completo para testar todos os modelos:

# Instalar dependências de desenvolvimento
pip install -e ".[dev]"

# Executar benchmark
python benchmark_models.py <arquivo_audio>

# Testar modelos específicos
python benchmark_models.py audio.wav --models tiny base medium

# Salvar relatório customizado
python benchmark_models.py audio.wav --output meu_relatorio.json

O benchmark testa:

  • ✅ Velocidade de processamento (REST API e WebSocket)
  • ✅ RTF (Real-Time Factor) de cada modelo
  • ✅ Verifica se o servidor está trocando os modelos corretamente
  • ✅ Gera relatórios visuais e JSON completo

Ver documentação completa em BENCHMARK.md.

Usando Makefile

O projeto inclui um Makefile para facilitar tarefas comuns:

# Verificação de código
make lint              # Verificar com flake8

# Build e publicação
make publish-test      # Publicar no TestPyPI
make publish           # Publicar no PyPI oficial

# Utilitários
make clean             # Limpar arquivos temporários
make help              # Ver todos os comandos

Para mais detalhes sobre desenvolvimento, ver CONTRIBUTING.md.

Troubleshooting

Erro de autenticação

Verifique se a API key está correta e ativa.

Timeout

Aumente o timeout:

client = STTClient(api_key="...", timeout=600)

Formato de áudio

Formatos suportados: WAV, MP3, FLAC, OGG, M4A

License

MIT License - Ver LICENSE

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

talklabs_stt-1.0.3.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

talklabs_stt-1.0.3-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file talklabs_stt-1.0.3.tar.gz.

File metadata

  • Download URL: talklabs_stt-1.0.3.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for talklabs_stt-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b95aeb37a31a786ba4e974af00f626be843f92623f29ce6310a49a3e088216e0
MD5 3a40e61aad2ff65976d962e0905a82a7
BLAKE2b-256 e0f6bcd0d30bdbc03ecb047770c1ecc78feed4142196cb7e4097758acc7452d6

See more details on using hashes here.

File details

Details for the file talklabs_stt-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: talklabs_stt-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for talklabs_stt-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3d039fcde6d3a2240d2e59d39f2c56d089fe31609887edd1e316b8dd23ac4112
MD5 3e014bc14ffc899369ed2a54d8ecbe08
BLAKE2b-256 447c95e397d504dd3f903be13fd4ba63d2b79d79768bf65bccf20c7cbaa47ec3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page