Skip to content

Commit dafef1a

Browse files
committed
feat: add support for passing a dict with an "audio" key
1 parent b1f6ae2 commit dafef1a

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/pyannoteai/sdk/client.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,17 @@ def _hash_md5(self, file: Union[str, Path]) -> str:
251251

252252
def upload(
253253
self,
254-
audio: str | Path,
254+
audio: str | Path | dict[str, str|Path],
255255
media_url: Optional[str] = None,
256256
callback: Optional[Callable] = None,
257257
) -> str:
258258
"""Upload audio file to pyannoteAI platform
259259
260260
Parameters
261261
----------
262-
audio : str or Path
263-
Audio file to be uploaded. Can be a "str" or "Path" instance: "audio.wav" or Path("audio.wav")
262+
audio : str or Path or dict
263+
Path to audio file to be uploaded. Can be a "str" or "Path" instance, or a dict with an
264+
"audio" key (e.g. {"audio": "/path/to/audio.wav"}).
264265
media_url : str, optional
265266
Unique identifier used to retrieve the uploaded audio file on the pyannoteAI platform.
266267
Any combination of letters {a-z, A-Z}, digits {0-9}, and {-./} characters prefixed
@@ -278,6 +279,13 @@ def upload(
278279
or "media://{md5-hash-of-audio-file}" otherwise.
279280
"""
280281

282+
if isinstance(audio, dict):
283+
if "audio" not in audio:
284+
raise ValueError(
285+
"When `audio` is a dict, it must provide the path to the audio file in 'audio' key."
286+
)
287+
audio = audio["audio"]
288+
281289
# get the total size of the file to upload
282290
# to provide progress information to the hook
283291
total_size = os.path.getsize(audio)

0 commit comments

Comments
 (0)