Sajjo commited on
Commit
792da40
·
verified ·
1 Parent(s): 3d84af1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -20
app.py CHANGED
@@ -48,27 +48,23 @@ def save_audio_text(audio, text):
48
  # Debugging to print out the structure of the audio variable
49
  print("Received audio data:", audio)
50
 
51
- try:
52
- # Check if audio is a dictionary and contains 'data'
53
- if isinstance(audio, dict) and 'data' in audio:
54
- audio_data = audio['data']
55
- audio_path = f"/tmp/recordings/line_{reader.current_index}.wav"
56
- text_path = f"/tmp/recordings/line_{reader.current_index}.txt"
 
 
57
 
58
- with open(audio_path, "wb") as f:
59
- f.write(audio_data)
60
-
61
- with open(text_path, "w") as f:
62
- f.write(text)
63
-
64
- # Move to the next line after saving
65
- next_line = reader.forward_line()
66
- return next_line
67
- else:
68
- return "Audio data is not in the expected format."
69
- except Exception as e:
70
- print(f"Error saving audio: {e}")
71
- return "Error saving audio."
72
 
73
  # Define the Gradio interface
74
  with gr.Blocks() as demo:
@@ -92,3 +88,4 @@ with gr.Blocks() as demo:
92
  save_button.click(fn=save_audio_text, inputs=[audio_record, current_line], outputs=current_line)
93
 
94
  demo.launch()
 
 
48
  # Debugging to print out the structure of the audio variable
49
  print("Received audio data:", audio)
50
 
51
+ # Check if audio is a dictionary and contains 'data'
52
+ if isinstance(audio, dict) and 'data' in audio:
53
+ audio_data = audio['data']
54
+ audio_path = f"/tmp/recordings/line_{reader.current_index}.wav"
55
+ text_path = f"/tmp/recordings/line_{reader.current_index}.txt"
56
+
57
+ with open(audio_path, "wb") as f:
58
+ f.write(audio_data)
59
 
60
+ with open(text_path, "w") as f:
61
+ f.write(text)
62
+
63
+ # Move to the next line after saving
64
+ next_line = reader.forward_line()
65
+ return next_line
66
+ else:
67
+ return "Audio data is not in the expected format."
 
 
 
 
 
 
68
 
69
  # Define the Gradio interface
70
  with gr.Blocks() as demo:
 
88
  save_button.click(fn=save_audio_text, inputs=[audio_record, current_line], outputs=current_line)
89
 
90
  demo.launch()
91
+