Metadata-Version: 2.1
Name: salute_speech
Version: 1.2.4
Summary: Sber Salute Speech API
Author-email: Maxim Moroz <maxim.moroz@gmail.com>
License: MIT License
        
        Copyright (c) 2024 Maxim Moroz <maxim.moroz@gmail.com>
        
        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.
        
Project-URL: Homepage, https://github.com/mmua/salute_speech
Project-URL: Repository, https://github.com/mmua/salute_speech.git
Keywords: speech
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.9
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Click>=8.1.7
Requires-Dist: python-dotenv>=1.0.1
Requires-Dist: requests>=2.32.3
Requires-Dist: pydub>=0.25.1

# Sber Salute Speech Python API

## Speech Recognition API

The `SaluteSpeechClient` provides an easy-to-use interface for transcribing audio files, similar to OpenAI's Whisper API but with async support.

### Installation

```bash
pip install salute_speech
```

### Quick Start

```python
from salute_speech.speech_recognition import SaluteSpeechClient
import asyncio

async def main():
    # Initialize the client
    client = SaluteSpeechClient(client_credentials="your_credentials_here")
    
    # Open and transcribe an audio file
    with open("audio.mp3", "rb") as audio_file:
        result = await client.audio.transcriptions.create(
            file=audio_file,
            language="ru-RU"
        )
        print(result.text)

# Run the async function
asyncio.run(main())
```

### API Reference

#### SaluteSpeechClient

##### `client.audio.transcriptions.create()`

Creates a transcription for the given audio file.

**Parameters:**
- `file` (BinaryIO): An audio file opened in binary mode
- `language` (str, optional): Language code for transcription. Defaults to "ru-RU"
- `prompt` (str, optional): Optional prompt to guide transcription
- `response_format` (str, optional): Format of the response. Currently only "text" is supported
- `poll_interval` (float, optional): Interval between status checks in seconds. Defaults to 1.0

**Returns:**
- `TranscriptionResponse` object with a `text` field containing the transcribed text

**Example:**
```python
async with open("meeting.mp3", "rb") as audio_file:
    result = await client.audio.transcriptions.create(
        file=audio_file,
        language="ru-RU",
        prompt="Important business meeting"
    )
    print(result.text)
```

### Supported Audio Formats

The service supports the following audio formats:
- PCM_S16LE (WAV)
- OPUS
- MP3
- FLAC
- ALAW
- MULAW

### Error Handling

The client may raise several types of exceptions:
- `TokenRequestError`: Issues with authentication
- `FileUploadError`: Problems during file upload
- `TaskStatusResponseError`: Errors while checking task status

It's recommended to wrap API calls in try-except blocks:

```python
try:
    result = await client.audio.transcriptions.create(file=audio_file)
except Exception as e:
    print(f"Transcription failed: {str(e)}")
```

## Command line interface 
* beware each audio channel is decoded so in many cases downmix to 1 channel is recommended

Usage:
```
salute_speech --help
```

Transcribe video to txt:
```
ffmpeg -i video.mp4 -ac 1 -ar 16000 audio.wav
salute_speech transcribe-audio audio.wav -o transcript.txt
```

Transcribe video to vtt:
```
ffmpeg -i video.mp4 -ac 1 -ar 16000 audio.wav
salute_speech transcribe-audio audio.wav -o transcript.vtt
```

Supported formats:
 * txt
 * vtt
 * srt
 * tsv

