Skip to content

Commit 1843663

Browse files
Add voice gender to Audio translation
1 parent cd61ee5 commit 1843663

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/lara_sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from ._client import LaraObject
22
from ._credentials import Credentials, AccessKey, AuthToken
33
from ._errors import LaraApiError, LaraError
4-
from ._translator import Memory, MemoryImport, TextBlock, TextResult, DetectPrediction, DetectResult, Memories, Translator, TranslatePriority, UseCache, Documents, Document, DocumentStatus, DocxExtractionParams, DocumentExtractionParams, GlossaryTerm, Audio, AudioStatus, AudioTranslator, AudioOptions, ImageParagraph, ImageTranslator
4+
from ._translator import Memory, MemoryImport, TextBlock, TextResult, DetectPrediction, DetectResult, Memories, Translator, TranslatePriority, UseCache, Documents, Document, DocumentStatus, DocxExtractionParams, DocumentExtractionParams, GlossaryTerm, Audio, AudioStatus, AudioTranslator, AudioOptions, VoiceGender, ImageParagraph, ImageTranslator
55

66
# This constant is auto-generated by the build script.
77
# Manual modifications will be overwritten and may cause unexpected behavior.

src/lara_sdk/_translator.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,18 @@ class AudioStatus(Enum):
370370
ERROR = 'error'
371371

372372

373+
class VoiceGender(Enum):
374+
MALE = 'male'
375+
FEMALE = 'female'
376+
377+
373378
@dataclass
374379
class AudioOptions:
375380
adapt_to: Optional[List[str]] = None
376381
glossaries: Optional[List[str]] = None
377382
no_trace: Optional[bool] = None
378383
style: Optional[TranslationStyle] = None
384+
voice_gender: Optional[VoiceGender] = None
379385

380386

381387
class Audio(LaraObject):
@@ -480,7 +486,8 @@ def __init__(self, client: LaraClient):
480486

481487
def upload(self, file_path: str, filename: str, target: str, source: Optional[str] = None,
482488
adapt_to: Optional[List[str]] = None, glossaries: Optional[List[str]] = None,
483-
no_trace: bool = False, style: Optional[TranslationStyle] = None) -> Audio:
489+
no_trace: bool = False, style: Optional[TranslationStyle] = None,
490+
voice_gender: Optional[VoiceGender] = None) -> Audio:
484491
with open(file_path, 'rb') as file_payload:
485492
response_data = self._client.get('/v2/audio/upload-url', {'filename': filename})
486493

@@ -504,6 +511,8 @@ def upload(self, file_path: str, filename: str, target: str, source: Optional[st
504511

505512
if style is not None:
506513
body['style'] = style
514+
if voice_gender is not None:
515+
body['voice_gender'] = voice_gender.value
507516

508517
headers = None
509518
if no_trace is True:
@@ -520,10 +529,12 @@ def download(self, id: str) -> bytes:
520529

521530
def translate(self, file_path: str, filename: str, target: str, source: Optional[str] = None,
522531
adapt_to: Optional[List[str]] = None, glossaries: Optional[List[str]] = None,
523-
no_trace: bool = False, style: Optional[TranslationStyle] = None) -> bytes:
532+
no_trace: bool = False, style: Optional[TranslationStyle] = None,
533+
voice_gender: Optional[VoiceGender] = None) -> bytes:
524534

525535
audio = self.upload(file_path=file_path, filename=filename, target=target, source=source,
526-
adapt_to=adapt_to, glossaries=glossaries, no_trace=no_trace, style=style)
536+
adapt_to=adapt_to, glossaries=glossaries, no_trace=no_trace, style=style,
537+
voice_gender=voice_gender)
527538

528539
max_wait_time = 60 * 15 # 15 minutes
529540
start = time.time()

0 commit comments

Comments
 (0)