Skip to content

Commit

Permalink
feat: add functions for more endpoints + some modifications (#41)
Browse files Browse the repository at this point in the history
* default settings endpoint support

* delete history item endpoint support

* fixed User class, updated Subscription

* multiple endpoints support

* gitignore

* Modifications as requested

* removed default_settings func, unnecessary

* modified edit, moved default_settings

* couple changes as requested
  • Loading branch information
theAbdoSabbagh authored Jun 4, 2023
1 parent f84f5c7 commit bfae742
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ __pycache__
.pytest_cache
.DS_Store
NOTES.md
test.py
3 changes: 3 additions & 0 deletions elevenlabs/api/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def audio(self) -> bytes:
if self._audio is None:
self._audio = API.get(url).content
return self._audio

def delete(self):
API.delete(f"{api_base_url_v1}/history/{self.history_item_id}")


class History(Listable, API):
Expand Down
18 changes: 17 additions & 1 deletion elevenlabs/api/user.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
from __future__ import annotations
from typing import Optional

from .base import API, api_base_url_v1


class Subscription(API):
tier: str
character_count: int
character_limit: int
can_extend_character_limit: bool
allowed_to_extend_character_limit: bool
next_character_count_reset_unix: int
voice_limit: int
professional_voice_limit: int
can_extend_voice_limit: bool
can_use_instant_voice_cloning: bool
can_use_professional_voice_cloning: bool
currency: Optional[str]
status: str

@classmethod
def from_api(cls) -> Subscription:
url = f"{api_base_url_v1}/user/subscription"
response = API.get(url).json()
return cls(**response)


class User(API):
subscription: Subscription
Expand Down
20 changes: 20 additions & 0 deletions elevenlabs/api/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,30 @@ def from_design(cls, voice_design: VoiceDesign):
def computed_settings(cls, v: VoiceSettings, values) -> VoiceSettings:
url = f"{api_base_url_v1}/voices/{values['voice_id']}/settings"
return v if v else VoiceSettings(**API.get(url).json())

@classmethod
def default_settings(cls):
url = f"{api_base_url_v1}/voices/settings/default"
return VoiceSettings(**API.get(url).json())

def delete(self):
API.delete(f"{api_base_url_v1}/voices/{self.voice_id}")

def edit_settings(self, voice_settings: VoiceSettings):
url = f"{api_base_url_v1}/voices/{self.voice_id}/settings/edit"
API.post(url, json=voice_settings.dict())

def edit(
self,
name: Optional[str] = None,
labels: Optional[str] = None,
description: Optional[str] = None
):
url = f"{api_base_url_v1}/voices/{self.voice_id}/edit"
self.name = name or self.name
self.labels = labels or self.labels
self.description = description or self.description
API.post(url, data=dict(name=self.name, labels=self.labels, description=self.description))

class Voices(Listable, API):
voices: List[Voice]
Expand Down

0 comments on commit bfae742

Please sign in to comment.