Skip to main content

AI audio detection and attribution Python SDK for tintap platform

Project description

tintap

AI Audio Detection & Attribution Solutions - Python SDK

About

tintap provides the most realistic audio AI detection platform. Over 1,000,000 creative minds use tintap to detect AI-generated audio and protect their content.

Installation

pip install tintap

Quick Start

Basic Usage

import tintap

# Create client
client = tintap.create_client(
    api_key='your-api-key-here',
    endpoint='http://your-api-server.com/api'  # Optional, defaults to localhost:3005
)

# Analyze audio file
try:
    result = client.analyze_audio('./audio.mp3')
    print('Analysis result:', result)
except tintap.TintapError as e:
    print('Analysis failed:', str(e))

Advanced Usage

from tintap import TintapClient
from pathlib import Path

# Initialize client with environment variable
client = TintapClient()  # Uses TINTAP_API_KEY env var

# Analyze from file path
result = client.analyze_audio('/path/to/audio.mp3')

# Analyze from Path object
audio_path = Path('./music/song.wav') 
result = client.analyze_audio(audio_path)

# Analyze from bytes
with open('./audio.mp3', 'rb') as f:
    audio_data = f.read()
    result = client.analyze_audio(audio_data, filename='audio.mp3')

# Analyze from file object
with open('./audio.mp3', 'rb') as f:
    result = client.analyze_audio(f, filename='audio.mp3')

Error Handling

import tintap
from tintap import TintapAPIError, TintapConnectionError, TintapAuthError

client = tintap.create_client(api_key='your-key')

try:
    result = client.analyze_audio('./audio.mp3')
    print(f"AI Detection: {result['result']['percentages']}")
    
except TintapAuthError:
    print("Invalid API key")
    
except TintapConnectionError:
    print("Failed to connect to API server")
    
except TintapAPIError as e:
    print(f"API error: {e}")
    
except tintap.TintapError as e:
    print(f"General error: {e}")

Features

  • AI-generated audio detection
  • Detailed segment analysis
  • Vocal segment classification
  • Real-time analysis
  • Multiple audio format support (FLAC, MP3, WAV, OGG)
  • Multiple input types (file paths, Path objects, bytes, file objects)
  • Comprehensive error handling
  • Type hints for better IDE support
  • Environment variable support

API Reference

TintapClient

Main client class for interacting with the tintap API.

Constructor

TintapClient(
    api_key: Optional[str] = None,
    endpoint: str = "http://localhost:3005/api",
    timeout: int = 120
)

Parameters:

  • api_key (str, optional) - Your tintap API key. If not provided, looks for TINTAP_API_KEY env var.
  • endpoint (str) - API endpoint URL. Defaults to localhost:3005.
  • timeout (int) - Request timeout in seconds. Defaults to 120.

Methods

analyze_audio()
analyze_audio(
    audio_file: Union[str, Path, BinaryIO, bytes],
    filename: Optional[str] = None
) -> Dict[str, Any]

Analyzes an audio file for AI-generated content detection.

Parameters:

  • audio_file - Path to audio file, Path object, file object, or bytes data
  • filename (str, optional) - Filename for the audio file (required when passing bytes/file object)

Returns: Dictionary with analysis results

Raises:

  • TintapAuthError - If API key is invalid
  • TintapValidationError - If input parameters are invalid
  • TintapAPIError - If API returns an error
  • TintapConnectionError - If connection fails
get_analysis()
get_analysis(analysis_id: str) -> Dict[str, Any]

Gets analysis results by ID (for future async processing).

get_info()
get_info() -> Dict[str, Any]

Gets API information and supported features.

test_connection()
test_connection() -> bool

Tests connection to the API server. Returns True if successful.

Helper Functions

create_client()

create_client(
    api_key: Optional[str] = None,
    endpoint: str = "http://localhost:3005/api",
    timeout: int = 120
) -> TintapClient

Creates a new tintap client instance.

Environment Variables

  • TINTAP_API_KEY - Your tintap API key

Response Format

{
    "id": "uuid-analysis-id",
    "status": "completed", 
    "filename": "audio.mp3",
    "timestamp": "2025-09-30T...",
    "result": {
        "percentages": {
            "ai": 85.2,
            "human": 14.8,
            "music": 0.0
        },
        "segments": [
            {
                "start": 0.0,
                "end": 5.2, 
                "class": "ai",
                "confidence": 0.95
            }
        ],
        "segmentsVox": [
            {
                "start": 0.0,
                "end": 3.1,
                "class": "ai_voice", 
                "confidence": 0.87
            }
        ]
    },
    "metadata": {
        "fileSize": 1024000,
        "mimeType": "audio/mpeg",
        "processingTime": 2.34
    }
}

Supported Audio Formats

  • 🎵 MP3 (audio/mpeg)
  • 🎵 WAV (audio/wav)
  • 🎵 FLAC (audio/flac)
  • 🎵 OGG (audio/ogg)
  • 🎵 AAC (audio/aac)

Examples

Batch Processing

import tintap
from pathlib import Path

client = tintap.create_client(api_key='your-key')

audio_files = Path('./music').glob('*.mp3')

for audio_file in audio_files:
    try:
        result = client.analyze_audio(audio_file)
        ai_percentage = result['result']['percentages']['ai']
        print(f"{audio_file.name}: {ai_percentage:.1f}% AI")
    except Exception as e:
        print(f"Failed to analyze {audio_file.name}: {e}")

Web Integration

from flask import Flask, request, jsonify
import tintap

app = Flask(__name__)
client = tintap.create_client()

@app.route('/analyze', methods=['POST'])
def analyze_audio():
    if 'file' not in request.files:
        return jsonify({'error': 'No file provided'}), 400
    
    file = request.files['file']
    
    try:
        result = client.analyze_audio(file, filename=file.filename)
        return jsonify(result)
    except tintap.TintapError as e:
        return jsonify({'error': str(e)}), 500

Development

Installing from source

git clone https://github.com/tintap/tintap-python.git
cd tintap-python
pip install -e .

Running tests

pip install -e ".[dev]"
pytest

Support

License

MIT License

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

tintap-0.1.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

tintap-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file tintap-0.1.0.tar.gz.

File metadata

  • Download URL: tintap-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.18

File hashes

Hashes for tintap-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a43636525062b1322f4aa2612de26f2af351bdedab05e60c3611c490a01b6e1b
MD5 a0673242e2b46f5aaca2e4e1e20392ad
BLAKE2b-256 76ea1311553c153c81ccb3a95b5dbdb4c978a1a049fbd388a14cb42ea1c71973

See more details on using hashes here.

File details

Details for the file tintap-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tintap-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.18

File hashes

Hashes for tintap-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa2660c8abdb833e460673a56fa7feecd236bdf409a54b94a8d4ed2dce47d7ac
MD5 78820d787f2e928b9e66889d505619a2
BLAKE2b-256 a4dd7e88003538e92ae196637a942c9a9a2767a8ce7baebfed12f08af7ffe83f

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