File size: 398 Bytes
a783939
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)