|
14 | 14 |
|
15 | 15 | logger = init_logger(__name__)
|
16 | 16 |
|
| 17 | +# prepare a WAV byte to prevent repeatedly generating it |
| 18 | +# Generate a 0.1 second silent audio file |
| 19 | +_SILENT_WAV_BYTES = None |
| 20 | +with io.BytesIO() as wav_buffer: |
| 21 | + with wave.open(wav_buffer, "wb") as wf: |
| 22 | + wf.setnchannels(1) # mono audio channel, standard configuration |
| 23 | + wf.setsampwidth(2) # 16 bit audio, common bit depth for wav file |
| 24 | + wf.setframerate(16000) # 16 kHz sample rate |
| 25 | + wf.writeframes(b"\x00\x00" * 1600) # 0.1 second of silence |
| 26 | + |
| 27 | + # retrieves the generated wav bytes, return |
| 28 | + _SILENT_WAV_BYTES = wav_buffer.getvalue() |
| 29 | + |
17 | 30 |
|
18 | 31 | class SingletonMeta(type):
|
19 | 32 | _instances = {}
|
@@ -80,19 +93,10 @@ def get_test_payload(model_type: str):
|
80 | 93 | return {"encoding_format": "float", "text_1": "Test", "test_2": "Test2"}
|
81 | 94 | case ModelType.transcription:
|
82 | 95 | # Generate a 0.1 second silent audio file
|
83 |
| - with io.BytesIO() as wav_buffer: |
84 |
| - with wave.open(wav_buffer, "wb") as wf: |
85 |
| - wf.setnchannels(1) # mono audio channel, standard configuration |
86 |
| - wf.setsampwidth(2) # 16 bit audio, common bit depth for wav file |
87 |
| - wf.setframerate(16000) # 16 kHz sample rate |
88 |
| - wf.writeframes(b"\x00\x00" * 1600) # 0.1 second of silence |
89 |
| - |
90 |
| - # retrieves the generated wav bytes, return |
91 |
| - wav_bytes = wav_buffer.getvalue() |
92 |
| - |
93 |
| - return { |
94 |
| - "file": ("empty.wav", wav_bytes, "audio/wav"), |
95 |
| - } |
| 96 | + if _SILENT_WAV_BYTES is not None: |
| 97 | + return { |
| 98 | + "file": ("empty.wav", _SILENT_WAV_BYTES, "audio/wav"), |
| 99 | + } |
96 | 100 |
|
97 | 101 |
|
98 | 102 | @staticmethod
|
|
0 commit comments