Metadata-Version: 2.4
Name: aiola
Version: 0.1.3
Summary: The official Python SDK for aiOla API - Speech-to-Text and Text-to-Speech
Project-URL: Homepage, https://aiola.ai
Project-URL: Repository, https://github.com/aiola-lab/aiola-python-sdk
Project-URL: Bug Tracker, https://github.com/aiola-lab/aiola-python-sdk/issues
Author-email: aiOla <support@aiola.ai>
Maintainer-email: aiOla <support@aiola.ai>
License: MIT License
        
        Copyright (c) 2025 Aiola
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: aiola,audio,microphone,speech,speech-to-text,stt,text-to-speech,tts
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: python-socketio[client]>=5.11
Provides-Extra: mic
Requires-Dist: numpy>=2.2.6; extra == 'mic'
Requires-Dist: sounddevice>=0.5.2; extra == 'mic'
Description-Content-Type: text/markdown

# aiOla Python SDK

The official Python SDK for the [aiOla](https://aiola.com) API, designed to work seamlessly in both synchronous and asynchronous environments.

## Installation

### Basic Installation

```bash
pip install aiola
# or
uv add aiola
```

### With Microphone Support

For microphone streaming functionality, install with the mic extra:

```bash
pip install 'aiola[mic]'
# or
uv add 'aiola[mic]'
```

## Usage

### Authentication

The aiOla SDK uses a **two-step authentication process**:

1. **Generate Access Token**: Use your API key to create a temporary access token, save it for later use
2. **Create Client**: Use the access token to instantiate the client

#### Step 1: Generate Access Token

```python
from aiola import AiolaClient

result = AiolaClient.grant_token(
    api_key='your-api-key'
)

access_token = result['accessToken'] 
session_id = result['sessionId']
```

#### Step 2: Create Client

```python
client = AiolaClient(
    access_token=access_token
)
```

#### Complete Example

```python
import os
from aiola import AiolaClient

def example():
    try:
        # Step 1: Generate access token
        result = AiolaClient.grant_token(
            api_key=os.getenv('AIOLA_API_KEY')
        )
        
        # Step 2: Create client
        client = AiolaClient(
            access_token=result['accessToken']
        )
        
        # Step 3: Use client for API calls
        with open('path/to/your/audio.wav', 'rb') as audio_file:
            transcript = client.stt.transcribe_file(
                file=audio_file,
                language='en'
            )
        
        print('Transcript:', transcript)
        
    except Exception as error:
        print('Error:', error)
```

#### Session Management

**Close Session:**
```python
# Terminates the session
result = AiolaClient.close_session(access_token)
print(f"Session closed at: {result['deletedAt']}")
```

#### Custom base URL (enterprises)

```python
result = AiolaClient.grant_token(
    api_key='your-api-key',
    auth_base_url='https://mycompany.auth.aiola.ai'
)

client = AiolaClient(
    access_token=result['accessToken'],
    base_url='https://mycompany.api.aiola.ai'
)
```

### Speech-to-Text – transcribe file

```python
import os
from aiola import AiolaClient

def transcribe_file():
    try:
        # Step 1: Generate access token
        result = AiolaClient.grant_token(
            api_key=os.getenv('AIOLA_API_KEY')
        )
        
        # Step 2: Create client
        client = AiolaClient(
            access_token=result['accessToken']
        )
        
        # Step 3: Transcribe file
        with open('path/to/your/audio.wav', 'rb') as audio_file:
            transcript = client.stt.transcribe_file(
                file=audio_file,
                language="e" # supported lan: en,de,fr,es,pr,zh,ja,it	 
            )

        print(transcript)
    except Exception as error:
        print('Error transcribing file:', error)
```

### Speech-to-Text – live streaming

```python
import os
import time
from aiola import AiolaClient, MicrophoneStream # pip install 'aiola[mic]'
from aiola.types import LiveEvents


def live_streaming():
    try:
        result = AiolaClient.grant_token(
            api_key=os.getenv("AIOLA_API_KEY") or "YOUR_API_KEY"
        )
        client = AiolaClient(access_token=result["accessToken"])
        connection = client.stt.stream(
            lang_code="en",             # supported lan: en,de,fr,es,pr,zh,ja,it
            keywords={"<word_to_catch>": "<word_transcribe>"}
            )

        @connection.on(LiveEvents.Transcript)
        def on_transcript(data):
            print("Transcript:", data.get("transcript", data))

        @connection.on(LiveEvents.Connect)
        def on_connect():
            print("Connected to streaming service")

        @connection.on(LiveEvents.Disconnect)
        def on_disconnect():
            print("Disconnected from streaming service")

        @connection.on(LiveEvents.Error)
        def on_error(error):
            print("Streaming error:", error)

        connection.connect()

        with MicrophoneStream(channels=1, samplerate=16000, blocksize=4096) as mic:
            mic.stream_to(connection)
            # Keep the main thread alive
            while True:
                time.sleep(0.1)

    except KeyboardInterrupt:
        print("Keyboard interrupt")
    except Exception as error:
        print("Error:", error)
    finally:
        connection.disconnect()
```

### Text-to-Speech

```python
import os
from aiola import AiolaClient

def create_file():
    try:
        result = AiolaClient.grant_token(
            api_key=os.getenv('AIOLA_API_KEY')
        )

        client = AiolaClient(
            access_token=result['accessToken']
        )
        
        audio = client.tts.synthesize(
            text='Hello, how can I help you today?',
            voice='jess',
            language='en'
        )

        with open('./audio.wav', 'wb') as f:
            for chunk in audio:
                f.write(chunk)
        
        print('Audio file created successfully')
    except Exception as error:
        print('Error creating audio file:', error)

create_file()
```

### Text-to-Speech – streaming

```python
import os
from aiola import AiolaClient

def stream_tts():
    try:
        result = AiolaClient.grant_token(
            api_key=os.getenv('AIOLA_API_KEY')
        )
        
        client = AiolaClient(
            access_token=result['accessToken']
        )
        
        stream = client.tts.stream(
            text='Hello, how can I help you today?',
            voice='jess',
            language='en'
        )

        audio_chunks = []
        for chunk in stream:
            audio_chunks.append(chunk)
        
        print('Audio chunks received:', len(audio_chunks))
    except Exception as error:
        print('Error streaming TTS:', error)
```

## Async Client

For asynchronous operations, use the `AsyncAiolaClient`:

### Async Speech-to-Text – file transcription

```python
import asyncio
import os
from aiola import AsyncAiolaClient

async def transcribe_file():
    try:
        result = await AsyncAiolaClient.grant_token(
            api_key=os.getenv('AIOLA_API_KEY')
        )
        
        client = AsyncAiolaClient(
            access_token=result['accessToken']
        )
        
        with open('path/to/your/audio.wav', 'rb') as audio_file:
            transcript = await client.stt.transcribe_file(
                file=audio_file,
                language="e" # supported lan: en,de,fr,es,pr,zh,ja,it	 
            )

        print(transcript)
    except Exception as error:
        print('Error transcribing file:', error)

if __name__ == "__main__":
    asyncio.run(transcribe_file())
```

### Async Text-to-Speech

```python
import asyncio
import os
from aiola import AsyncAiolaClient

async def create_audio_file():
    try:
        result = await AsyncAiolaClient.grant_token(
            api_key=os.getenv('AIOLA_API_KEY')
        )
        
        client = AsyncAiolaClient(
            access_token=result['accessToken']
        )
        
        audio = client.tts.synthesize(
            text='Hello, how can I help you today?',
            voice='jess',
            language='en'
        )

        with open('./audio.wav', 'wb') as f:
            async for chunk in audio:
                f.write(chunk)
        
        print('Audio file created successfully')
    except Exception as error:
        print('Error creating audio file:', error)

if __name__ == "__main__":
    asyncio.run(create_audio_file())
```

### Async Text-to-Speech – streaming

```python
import asyncio
import os
from aiola import AsyncAiolaClient

async def stream_tts():
    try:
        result = await AsyncAiolaClient.grant_token(
            api_key=os.getenv('AIOLA_API_KEY')
        )
        
        client = AsyncAiolaClient(
            access_token=result['accessToken']
        )
        
        stream = client.tts.stream(
            text='Hello, how can I help you today?',
            voice='jess',
            language='en'
        )

        audio_chunks = []
        async for chunk in stream:
            audio_chunks.append(chunk)
        
        print('Audio chunks received:', len(audio_chunks))
    except Exception as error:
        print('Error streaming TTS:', error)

if __name__ == "__main__":
    asyncio.run(stream_tts())
```

## Requirements

- Python 3.10+
- For microphone streaming functionality: Install with `pip install 'aiola[mic]'`

## Examples

The SDK includes several example scripts in the `examples/` directory.
