File size: 742 Bytes
9410704 | 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 | import os
import tempfile
import httpx
from typing import Sequence, Generator
IN_GITHUB = "GITHUB_ACTIONS" in os.environ
DEFAULT_VOICE = "IRHApOXLvnW57QJPQH2P"
DEFAULT_TEXT = "Hello"
DEFAULT_MODEL = "eleven_multilingual_v2"
DEFAULT_VOICE_FILE = "tests/fixtures/voice_sample.mp3"
def as_local_files(urls: Sequence[str]) -> Generator[str, None, None]:
"""Util to download files from urls and return local file paths"""
temp_files = []
for url in urls:
response = httpx.get(url)
temp_file = tempfile.NamedTemporaryFile()
temp_file.write(response.content)
temp_files.append(temp_file)
yield temp_file.name
# Remove the files
for temp_file in temp_files:
temp_file.close()
|