Spaces:
Sleeping
Sleeping
Commit
·
48eebae
1
Parent(s):
4ccd185
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,4 +9,53 @@ if st.button("Analyze"):
|
|
| 9 |
# Perform inference using the loaded model
|
| 10 |
result = model(input_text)
|
| 11 |
st.write("Prediction:", result[0]['label'], "| Score:", result[0]['score'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
|
|
|
| 9 |
# Perform inference using the loaded model
|
| 10 |
result = model(input_text)
|
| 11 |
st.write("Prediction:", result[0]['label'], "| Score:", result[0]['score'])
|
| 12 |
+
|
| 13 |
+
###
|
| 14 |
+
def recording_storing():
|
| 15 |
+
chunk = 1024 # Record in chunks of 1024 samples
|
| 16 |
+
sample_format = pyaudio.paInt16 # 16 bits per sample
|
| 17 |
+
channels = 1
|
| 18 |
+
fs = 44100 # Record at 44100 samples per second
|
| 19 |
+
seconds = 4
|
| 20 |
+
# filename = "output.wav"
|
| 21 |
+
|
| 22 |
+
p = pyaudio.PyAudio() # Create an interface to PortAudio
|
| 23 |
+
|
| 24 |
+
print('Recording')
|
| 25 |
+
|
| 26 |
+
stream = p.open(format=sample_format,
|
| 27 |
+
channels=channels,
|
| 28 |
+
rate=fs,
|
| 29 |
+
frames_per_buffer=chunk,
|
| 30 |
+
input=True)
|
| 31 |
+
|
| 32 |
+
frames = [] # Initialize array to store frames
|
| 33 |
+
|
| 34 |
+
# Store data in chunks for 3 seconds
|
| 35 |
+
for i in range(0, int(fs / chunk * seconds)):
|
| 36 |
+
data = stream.read(chunk)
|
| 37 |
+
frames.append(data)
|
| 38 |
+
|
| 39 |
+
# Stop and close the stream
|
| 40 |
+
stream.stop_stream()
|
| 41 |
+
stream.close()
|
| 42 |
+
# Terminate the PortAudio interface
|
| 43 |
+
p.terminate()
|
| 44 |
+
|
| 45 |
+
print('Finished recording')
|
| 46 |
+
|
| 47 |
+
# Save the recorded data as a WAV file
|
| 48 |
+
wf = wave.open(filename, 'wb')
|
| 49 |
+
wf.setnchannels(channels)
|
| 50 |
+
wf.setsampwidth(p.get_sample_size(sample_format))
|
| 51 |
+
wf.setframerate(fs)
|
| 52 |
+
wf.writeframes(b''.join(frames))
|
| 53 |
+
wf.close()
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
return "recorded"
|
| 58 |
+
|
| 59 |
+
audio = recording_storing()
|
| 60 |
+
print(audio)
|
| 61 |
|