Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -49,13 +49,34 @@ amplitude_scaling_factor = 10.0
|
|
49 |
# -----------------Record----------------- #
|
50 |
|
51 |
def record(audio):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
try:
|
|
|
|
|
|
|
|
|
|
|
53 |
sr, data = audio
|
|
|
|
|
54 |
wavio.write("recorded.wav", data, sr)
|
|
|
|
|
55 |
main()
|
|
|
|
|
56 |
return f"Audio receive correctly"
|
57 |
except Exception as e:
|
58 |
-
return
|
|
|
59 |
|
60 |
|
61 |
# -----------------Filter----------------- #
|
|
|
49 |
# -----------------Record----------------- #
|
50 |
|
51 |
def record(audio):
|
52 |
+
"""
|
53 |
+
This function records audio and writes it to a .wav file.
|
54 |
+
|
55 |
+
Parameters:
|
56 |
+
audio (tuple): A tuple containing the sample rate and the audio data.
|
57 |
+
|
58 |
+
Returns:
|
59 |
+
str: A success message if the audio is recorded correctly, otherwise an error message.
|
60 |
+
"""
|
61 |
try:
|
62 |
+
# Check if the audio tuple contains exactly two elements
|
63 |
+
if len(audio) != 2:
|
64 |
+
return f"Error: Expected a tuple with 2 elements, but got {len(audio)}"
|
65 |
+
|
66 |
+
# Unpack the sample rate and data from the audio tuple
|
67 |
sr, data = audio
|
68 |
+
|
69 |
+
# Write the audio data to a .wav file
|
70 |
wavio.write("recorded.wav", data, sr)
|
71 |
+
|
72 |
+
# Call the filtered function to apply the bandpass filter to the audio data
|
73 |
main()
|
74 |
+
|
75 |
+
# Return a success message
|
76 |
return f"Audio receive correctly"
|
77 |
except Exception as e:
|
78 |
+
# If an error occurs, return an error message
|
79 |
+
return f"Error: {str(e)}"
|
80 |
|
81 |
|
82 |
# -----------------Filter----------------- #
|