RamAnanth1 commited on
Commit
8d2cd0e
·
1 Parent(s): 38d7cc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -24,11 +24,28 @@ def _read_file(filename, chunk_size=5242880):
24
  break
25
  yield data
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  def get_audio_from_upload(audio):
28
  upload_response = requests.post(
29
  upload_endpoint,
30
  headers=headers,
31
- data=_read_file(audio))
32
  print(upload_response.json())
33
  return
34
 
 
24
  break
25
  yield data
26
 
27
+ def _read_array(audio, chunk_size=5242880):
28
+ """Like _read_file but for array - creates temporary unsaved "file" from sample rate and audio np.array"""
29
+ sr, aud = audio
30
+
31
+ # Create temporary "file" and write data to it
32
+ bytes_wav = bytes()
33
+ temp_file = io.BytesIO(bytes_wav)
34
+ write(temp_file, sr, aud)
35
+
36
+ while True:
37
+ data = temp_file.read(chunk_size)
38
+ if not data:
39
+ break
40
+ yield data
41
+
42
+
43
+
44
  def get_audio_from_upload(audio):
45
  upload_response = requests.post(
46
  upload_endpoint,
47
  headers=headers,
48
+ data=_read_array(audio))
49
  print(upload_response.json())
50
  return
51