chotam's picture
Deploy fraud detector API
a783939
raw
history blame contribute delete
398 Bytes
import contextlib
import os
import tempfile
from typing import Iterator
@contextlib.contextmanager
def temp_audio(data: bytes, suffix: str) -> Iterator[str]:
fd, path = tempfile.mkstemp(suffix=suffix, prefix="fd_")
try:
with os.fdopen(fd, "wb") as f:
f.write(data)
yield path
finally:
with contextlib.suppress(OSError):
os.remove(path)