Spaces:
Sleeping
Sleeping
| import tempfile | |
| import wave | |
| import struct | |
| import requests | |
| with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as tmp: | |
| filename = tmp.name | |
| sample_rate = 16000 | |
| duration = 6 | |
| nframes = sample_rate * duration | |
| with wave.open(filename, 'wb') as wf: | |
| wf.setnchannels(1) | |
| wf.setsampwidth(2) | |
| wf.setframerate(sample_rate) | |
| for _ in range(nframes): | |
| wf.writeframes(struct.pack('<h', 0)) | |
| with open(filename, 'rb') as f: | |
| files = {'audio': ('test.wav', f, 'audio/wav')} | |
| data = {'duration': str(duration)} | |
| r = requests.post('http://localhost:3000/api/analyze', files=files, data=data, timeout=30) | |
| print('status', r.status_code) | |
| print('body', r.text[:1000]) | |