|
5 | 5 | import pytest
|
6 | 6 | import asyncio
|
7 | 7 | import logging
|
| 8 | +import os |
| 9 | +from jigsawstack import AsyncJigsawStack |
8 | 10 |
|
9 | 11 | logging.basicConfig(level=logging.INFO)
|
10 | 12 | logger = logging.getLogger(__name__)
|
11 | 13 |
|
12 | 14 |
|
13 |
| -def test_async_speaker_voice_accents_response(): |
| 15 | +def test_text_to_speech(): |
| 16 | + async def _test(): |
| 17 | + client = AsyncJigsawStack() |
| 18 | + |
| 19 | + """Test converting text to speech""" |
| 20 | + try: |
| 21 | + response = client.audio.text_to_speech( |
| 22 | + { |
| 23 | + "text": "Hello world, this is a test of the JigsawStack text to speech API." |
| 24 | + } |
| 25 | + ) |
| 26 | + print("Text to speech response:", response) |
| 27 | + assert response["success"] == True |
| 28 | + |
| 29 | + except Exception as e: |
| 30 | + print(f"Error in text_to_speech test: {e}") |
| 31 | + |
| 32 | + asyncio.run(_test()) |
| 33 | + |
| 34 | + |
| 35 | +def test_speaker_voice_accents(): |
| 36 | + client = AsyncJigsawStack() |
| 37 | + |
| 38 | + """Test getting available voice accents""" |
| 39 | + try: |
| 40 | + response = client.audio.speaker_voice_accents() |
| 41 | + print("Speaker voice accents response:", response) |
| 42 | + assert response["success"] == True |
| 43 | + |
| 44 | + except Exception as e: |
| 45 | + print(f"Error in speaker voice accents test: {e}") |
| 46 | + |
| 47 | + |
| 48 | +def test_create_clone(): |
| 49 | + async def _test(): |
| 50 | + client = AsyncJigsawStack() |
| 51 | + |
| 52 | + """Test creating a voice clone with URL""" |
| 53 | + try: |
| 54 | + audio_url = ( |
| 55 | + "https://jigsawstack.com/audio/test.mp3" # Replace with an actual URL |
| 56 | + ) |
| 57 | + clone_response_url = client.audio.create_clone( |
| 58 | + {"url": audio_url, "name": "Test Voice Clone URL"} |
| 59 | + ) |
| 60 | + |
| 61 | + assert clone_response_url["success"] == True |
| 62 | + |
| 63 | + clone_response_file_store_key = client.audio.create_clone( |
| 64 | + { |
| 65 | + "file_store_key": "hello_audio", |
| 66 | + "name": "Test Voice Clone File Store Key", |
| 67 | + } |
| 68 | + ) |
| 69 | + |
| 70 | + assert clone_response_file_store_key["success"] == True |
| 71 | + |
| 72 | + except Exception as e: |
| 73 | + print(f"Error in voice_cloning test: {e}") |
| 74 | + |
| 75 | + asyncio.run(_test()) |
| 76 | + |
| 77 | + |
| 78 | +def test_get_clones(): |
| 79 | + async def _test(): |
| 80 | + client = AsyncJigsawStack() |
| 81 | + """Test getting voice clones""" |
| 82 | + try: |
| 83 | + # List available voice clones |
| 84 | + clones_response = client.audio.get_clones({"limit": 10, "page": 1}) |
| 85 | + |
| 86 | + assert clones_response["success"] == True |
| 87 | + |
| 88 | + except Exception as e: |
| 89 | + print(f"Error in voice_cloning test: {e}") |
| 90 | + |
| 91 | + asyncio.run(_test()) |
| 92 | + |
| 93 | + |
| 94 | +def test_delete_clone(): |
14 | 95 | async def _test():
|
15 | 96 | client = AsyncJigsawStack()
|
| 97 | + """Test getting a voice clone""" |
16 | 98 | try:
|
17 |
| - result = await client.audio.speaker_voice_accents() |
18 |
| - assert result["success"] == True |
19 |
| - except JigsawStackError as e: |
20 |
| - pytest.fail(f"Unexpected JigsawStackError: {e}") |
| 99 | + create_clone_response = client.audio.create_clone( |
| 100 | + {"name": "Test Voice Clone URL", "file_store_key": "hello_audio"} |
| 101 | + ) |
| 102 | + clones = client.audio.get_clones() |
| 103 | + print("Clones:", clones) |
| 104 | + clone_id = clones[0]["id"] |
| 105 | + delete_clone_response = client.audio.delete_clone(clone_id) |
| 106 | + print("Delete clone response:", delete_clone_response) |
| 107 | + assert delete_clone_response["success"] == True |
| 108 | + |
| 109 | + except Exception as e: |
| 110 | + print(f"Error in get_clone test: {e}") |
21 | 111 |
|
22 | 112 | asyncio.run(_test())
|
0 commit comments