voicebot / utils /helpers.py
datbkpro's picture
voicebot offical
dbf2148
raw
history blame contribute delete
445 Bytes
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