audial-sdk 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- audial/__init__.py +32 -0
- audial/api/__init__.py +15 -0
- audial/api/auth.py +117 -0
- audial/api/constants.py +59 -0
- audial/api/exceptions.py +18 -0
- audial/api/proxy.py +872 -0
- audial/cli/__init__.py +7 -0
- audial/cli/commands.py +392 -0
- audial/functions/__init__.py +19 -0
- audial/functions/analyze.py +147 -0
- audial/functions/master.py +276 -0
- audial/functions/midi.py +285 -0
- audial/functions/samples.py +498 -0
- audial/functions/segment.py +409 -0
- audial/functions/stem_split.py +329 -0
- audial/utils/__init__.py +20 -0
- audial/utils/config.py +156 -0
- audial/utils/file_utils.py +88 -0
- audial/utils/results_manager.py +116 -0
- audial_sdk-1.0.0.dist-info/METADATA +430 -0
- audial_sdk-1.0.0.dist-info/RECORD +25 -0
- audial_sdk-1.0.0.dist-info/WHEEL +5 -0
- audial_sdk-1.0.0.dist-info/entry_points.txt +2 -0
- audial_sdk-1.0.0.dist-info/licenses/LICENSE +21 -0
- audial_sdk-1.0.0.dist-info/top_level.txt +1 -0
audial/__init__.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Audial SDK: A Python package for interacting with the Audial audio processing API.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
__version__ = "1.0.0"
|
|
6
|
+
|
|
7
|
+
# Import and re-export public functions
|
|
8
|
+
from audial.functions.stem_split import stem_split
|
|
9
|
+
from audial.functions.analyze import analyze
|
|
10
|
+
from audial.functions.segment import segment
|
|
11
|
+
from audial.functions.master import master
|
|
12
|
+
from audial.functions.samples import generate_samples
|
|
13
|
+
from audial.functions.midi import generate_midi
|
|
14
|
+
|
|
15
|
+
# Import config module
|
|
16
|
+
from audial.utils import config
|
|
17
|
+
|
|
18
|
+
# Import exceptions
|
|
19
|
+
from audial.api.exceptions import AudialError, AudialAuthError, AudialAPIError
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"stem_split",
|
|
23
|
+
"analyze",
|
|
24
|
+
"segment",
|
|
25
|
+
"master",
|
|
26
|
+
"generate_samples",
|
|
27
|
+
"generate_midi",
|
|
28
|
+
"config",
|
|
29
|
+
"AudialError",
|
|
30
|
+
"AudialAuthError",
|
|
31
|
+
"AudialAPIError",
|
|
32
|
+
]
|
audial/api/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""
|
|
2
|
+
API client for the Audial SDK.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from audial.api.proxy import AudialProxy
|
|
6
|
+
from audial.api.auth import get_auth_headers
|
|
7
|
+
from audial.api.exceptions import AudialError, AudialAuthError, AudialAPIError
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"AudialProxy",
|
|
11
|
+
"get_auth_headers",
|
|
12
|
+
"AudialError",
|
|
13
|
+
"AudialAuthError",
|
|
14
|
+
"AudialAPIError",
|
|
15
|
+
]
|
audial/api/auth.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Authentication utilities for the Audial SDK.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import Dict
|
|
6
|
+
import uuid
|
|
7
|
+
import os
|
|
8
|
+
import json
|
|
9
|
+
|
|
10
|
+
from audial.api.exceptions import AudialAuthError
|
|
11
|
+
from audial.utils.config import get_user_id
|
|
12
|
+
|
|
13
|
+
def load_dotenv():
|
|
14
|
+
"""
|
|
15
|
+
Load environment variables from .env file.
|
|
16
|
+
"""
|
|
17
|
+
try:
|
|
18
|
+
# Check if .env file exists
|
|
19
|
+
if os.path.exists('.env'):
|
|
20
|
+
with open('.env', 'r') as f:
|
|
21
|
+
for line in f:
|
|
22
|
+
line = line.strip()
|
|
23
|
+
if line and not line.startswith('#'):
|
|
24
|
+
key, value = line.split('=', 1)
|
|
25
|
+
# Remove quotes if present
|
|
26
|
+
value = value.strip().strip('"\'')
|
|
27
|
+
os.environ[key.strip()] = value
|
|
28
|
+
except Exception as e:
|
|
29
|
+
print(f"Warning: Could not load .env file: {str(e)}")
|
|
30
|
+
|
|
31
|
+
def get_api_key():
|
|
32
|
+
"""
|
|
33
|
+
Get the API key from environment or config file.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
str: The API key.
|
|
37
|
+
|
|
38
|
+
Raises:
|
|
39
|
+
AudialAuthError: If no API key is available.
|
|
40
|
+
"""
|
|
41
|
+
# Try to load from .env file first
|
|
42
|
+
load_dotenv()
|
|
43
|
+
|
|
44
|
+
# Check environment variable
|
|
45
|
+
api_key = os.environ.get("AUDIAL_API_KEY")
|
|
46
|
+
|
|
47
|
+
if not api_key:
|
|
48
|
+
# Check config file
|
|
49
|
+
config_dir = os.path.expanduser("~/.audial")
|
|
50
|
+
config_file = os.path.join(config_dir, "config.json")
|
|
51
|
+
|
|
52
|
+
if os.path.exists(config_file):
|
|
53
|
+
try:
|
|
54
|
+
with open(config_file, 'r') as f:
|
|
55
|
+
config = json.load(f)
|
|
56
|
+
api_key = config.get("api_key")
|
|
57
|
+
except Exception as e:
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
# If still no API key, raise an error
|
|
61
|
+
if not api_key:
|
|
62
|
+
raise AudialAuthError(
|
|
63
|
+
"No API key available. Please set your API key using "
|
|
64
|
+
"audial.config.set_api_key() or by setting the AUDIAL_API_KEY "
|
|
65
|
+
"environment variable."
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
return api_key
|
|
69
|
+
|
|
70
|
+
def get_auth_headers(api_key: str = None) -> Dict[str, str]:
|
|
71
|
+
"""
|
|
72
|
+
Get the authentication headers for API requests.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
api_key (str, optional): The API key to use. If not provided, it will be loaded from the configuration.
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
Dict[str, str]: The authentication headers.
|
|
79
|
+
|
|
80
|
+
Raises:
|
|
81
|
+
AudialAuthError: If no API key is available.
|
|
82
|
+
"""
|
|
83
|
+
# Get API key from config if not provided
|
|
84
|
+
if api_key is None:
|
|
85
|
+
api_key = get_api_key()
|
|
86
|
+
|
|
87
|
+
# Check if API key is available
|
|
88
|
+
if not api_key:
|
|
89
|
+
raise AudialAuthError(
|
|
90
|
+
"No API key available. Please set your API key using "
|
|
91
|
+
"audial.config.set_api_key() or by setting the AUDIAL_API_KEY "
|
|
92
|
+
"environment variable."
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# Get user ID from configuration
|
|
96
|
+
user_id = get_user_id()
|
|
97
|
+
if not user_id:
|
|
98
|
+
raise AudialAuthError(
|
|
99
|
+
"No user ID available. Please set your user ID using "
|
|
100
|
+
"audial.config.set_user_id() or by setting the AUDIAL_USER_ID "
|
|
101
|
+
"environment variable."
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# Generate request ID for tracking
|
|
105
|
+
request_id = str(uuid.uuid4())
|
|
106
|
+
|
|
107
|
+
# Return headers matching exactly what the frontend sends
|
|
108
|
+
# This is critical - including both x-api-key and Authorization headers,
|
|
109
|
+
# as well as the required x-user-id header
|
|
110
|
+
# print(f"Using API Key: {api_key}, Using x-user-id: {user_id}")
|
|
111
|
+
return {
|
|
112
|
+
# "Authorization": f"Bearer {api_key}",
|
|
113
|
+
"x-api-key": api_key,
|
|
114
|
+
"x-user-id": user_id,
|
|
115
|
+
"Content-Type": "application/json",
|
|
116
|
+
"X-Request-ID": request_id
|
|
117
|
+
}
|
audial/api/constants.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Constants for the Audial API.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# Base API URL - using the auth server as proxy
|
|
6
|
+
# This endpoint will be responsible for routing to the actual API endpoints
|
|
7
|
+
API_BASE_URL = "https://starfish-app-2x28e.ondigitalocean.app/api"
|
|
8
|
+
AUTH_SERVER_URL = "https://starfish-app-2x28e.ondigitalocean.app/api/proxy"
|
|
9
|
+
|
|
10
|
+
# Function names as defined in the API
|
|
11
|
+
FUNCTION_STEM_SPLITTER = "stem-splitter"
|
|
12
|
+
FUNCTION_PRIMARY_ANALYSIS = "primary-analysis"
|
|
13
|
+
FUNCTION_SEGMENTATION = "segmentation"
|
|
14
|
+
FUNCTION_MASTERING = "mastering"
|
|
15
|
+
FUNCTION_SAMPLE_PACK = "sample-pack"
|
|
16
|
+
FUNCTION_GENERATE_MIDI = "generate-midi"
|
|
17
|
+
|
|
18
|
+
# Execution types
|
|
19
|
+
EXECUTION_TYPE_STEM = "stem"
|
|
20
|
+
EXECUTION_TYPE_MODIFIED = "modified"
|
|
21
|
+
EXECUTION_TYPE_MASTER = "master"
|
|
22
|
+
EXECUTION_TYPE_MIDI = "midi"
|
|
23
|
+
EXECUTION_TYPE_SAMPLES = "samples"
|
|
24
|
+
EXECUTION_TYPE_SEGMENTATION = "segmentation"
|
|
25
|
+
|
|
26
|
+
# Execution states
|
|
27
|
+
EXECUTION_STATE_CREATED = "created"
|
|
28
|
+
EXECUTION_STATE_INITIALIZED = "initialized"
|
|
29
|
+
EXECUTION_STATE_PROCESSING = "processing"
|
|
30
|
+
EXECUTION_STATE_COMPLETED = "completed"
|
|
31
|
+
EXECUTION_STATE_FAILED = "failed"
|
|
32
|
+
|
|
33
|
+
# Default stem options
|
|
34
|
+
DEFAULT_STEM_OPTIONS = ["vocals", "drums", "bass", "other"]
|
|
35
|
+
|
|
36
|
+
# Available stem options
|
|
37
|
+
ALL_STEM_OPTIONS = [
|
|
38
|
+
"vocals",
|
|
39
|
+
"drums",
|
|
40
|
+
"bass",
|
|
41
|
+
"other",
|
|
42
|
+
"full_song_without_vocals",
|
|
43
|
+
"full_song_without_drums",
|
|
44
|
+
"full_song_without_bass",
|
|
45
|
+
"full_song_without_other"
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
# Default polling interval for checking execution status (in seconds)
|
|
49
|
+
DEFAULT_POLLING_INTERVAL = 2
|
|
50
|
+
|
|
51
|
+
# Maximum number of retries for API requests
|
|
52
|
+
MAX_RETRIES = 3
|
|
53
|
+
|
|
54
|
+
# Timeout for API requests (in seconds)
|
|
55
|
+
REQUEST_TIMEOUT = 60
|
|
56
|
+
|
|
57
|
+
# Default values for segmentation
|
|
58
|
+
DEFAULT_SEGMENTATION_COMPONENTS = ["intro", "verse", "chorus", "outro"]
|
|
59
|
+
DEFAULT_SEGMENTATION_FEATURES = ["energy", "tempo", "loudness"]
|
audial/api/exceptions.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Exceptions for the Audial SDK.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
class AudialError(Exception):
|
|
6
|
+
"""Base exception for all Audial SDK errors."""
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
class AudialAuthError(AudialError):
|
|
10
|
+
"""Exception raised for authentication errors."""
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
class AudialAPIError(AudialError):
|
|
14
|
+
"""Exception raised for API errors."""
|
|
15
|
+
def __init__(self, message, status_code=None, response=None):
|
|
16
|
+
self.status_code = status_code
|
|
17
|
+
self.response = response
|
|
18
|
+
super().__init__(message)
|