File size: 445 Bytes
dbf2148
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import numpy as np
import io
import soundfile as sf

def numpy_to_mp3(audio_array: np.ndarray, sampling_rate: int = 24000) -> bytes:
    """Convert numpy array to MP3 bytes"""
    buffer = io.BytesIO()
    sf.write(buffer, audio_array, sampling_rate, format='mp3')
    buffer.seek(0)
    return buffer.read()

def validate_api_key(api_key: str) -> bool:
    """Validate Groq API key"""
    return api_key is not None and len(api_key.strip()) > 0