Chris STC commited on
Commit
c1228d7
1 Parent(s): 929c2b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -9,13 +9,21 @@ from scipy.io.wavfile import write
9
  tts = None
10
  audio_base64 = ""
11
 
12
-
13
  def audio_to_base64(sample_rate, audio_data):
 
14
  buffer = io.BytesIO()
15
- write(buffer, sample_rate, audio_data)
16
- base64_audio = base64.b64encode(buffer.getvalue()).decode('utf-8')
17
- buffer.close()
18
- return base64_audio
 
 
 
 
 
 
 
 
19
 
20
  def main():
21
  logging.basicConfig(level=logging.INFO)
 
9
  tts = None
10
  audio_base64 = ""
11
 
 
12
  def audio_to_base64(sample_rate, audio_data):
13
+ # Create a buffer to hold the WAV file
14
  buffer = io.BytesIO()
15
+ with wave.open(buffer, 'w') as wav_file:
16
+ # Set the parameters for the WAV file
17
+ wav_file.setnchannels(1)
18
+ wav_file.setsampwidth(2) # 16-bit
19
+ wav_file.setframerate(sample_rate)
20
+ wav_file.writeframes(audio_data.tobytes())
21
+
22
+ # Get the content of the buffer and encode it as Base64
23
+ wav_bytes = buffer.getvalue()
24
+ base64_str = base64.b64encode(wav_bytes).decode('utf-8')
25
+
26
+ return base64_str
27
 
28
  def main():
29
  logging.basicConfig(level=logging.INFO)