-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathconftest.py
More file actions
82 lines (60 loc) · 2.01 KB
/
conftest.py
File metadata and controls
82 lines (60 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""Fixtures for integration tests."""
from __future__ import annotations
import os
from pathlib import Path
import pytest
from dotenv import load_dotenv
from fishaudio import AsyncFishAudio, FishAudio
load_dotenv()
# Create output directory for test audio files
OUTPUT_DIR = Path("output")
OUTPUT_DIR.mkdir(exist_ok=True)
# Test reference voice ID for testing reference voice features
TEST_REFERENCE_ID = "ca3007f96ae7499ab87d27ea3599956a"
@pytest.fixture
def api_key():
"""Get API key from environment."""
key = os.getenv("FISH_API_KEY")
if not key:
pytest.skip("No API key available (set FISH_API_KEY)")
return key
@pytest.fixture(scope="function")
def client(api_key):
"""Sync Fish Audio client (function-scoped for test isolation)."""
import time
client = FishAudio(api_key=api_key)
yield client
client.close()
# Brief delay to avoid API rate limits on WebSocket connections
time.sleep(0.3)
@pytest.fixture
async def async_client(api_key):
"""Async Fish Audio client."""
import asyncio
client = AsyncFishAudio(api_key=api_key)
yield client
await client.close()
# Brief delay to avoid API rate limits on WebSocket connections
await asyncio.sleep(0.3)
@pytest.fixture
def save_audio():
"""Fixture that provides a helper to save audio chunks to the output directory.
Returns:
A callable that takes audio chunks and filename and saves to output/
"""
def _save(audio: bytes | list[bytes], filename: str) -> Path:
"""Save audio to output directory.
Args:
audio: Audio bytes or list of audio byte chunks
filename: Name of the output file (including extension)
Returns:
Path to the saved file
"""
if isinstance(audio, bytes):
complete_audio = audio
else:
complete_audio = b"".join(audio)
output_file = OUTPUT_DIR / filename
output_file.write_bytes(complete_audio)
return output_file
return _save