35 lines
873 B
Python
35 lines
873 B
Python
from abc import ABC, abstractmethod
|
|
|
|
class BaseAudioService(ABC):
|
|
|
|
def __init__(self, api_key, api_secret):
|
|
self.api_key = api_key
|
|
self.api_secret = api_secret
|
|
|
|
@abstractmethod
|
|
def get_token(self):
|
|
pass
|
|
|
|
@abstractmethod
|
|
def synthesize_speech(self, text, language='en'):
|
|
pass
|
|
|
|
@abstractmethod
|
|
def synthesize_speech_raw(self, text, language='en'):
|
|
"""
|
|
Generate speech from text and return the raw audio data directly
|
|
without storing it or creating a URL
|
|
|
|
Args:
|
|
text (str): The text to convert to speech
|
|
language (str, optional): Language code. Defaults to 'en'.
|
|
|
|
Returns:
|
|
bytes: Raw audio data
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def recognize_speech(self, audio_data, language='en') -> str:
|
|
pass
|