Demo Update 28
This commit is contained in:
@@ -341,10 +341,10 @@ def on_speech_started(session_id):
|
|||||||
# If AI is speaking, we need to interrupt it
|
# If AI is speaking, we need to interrupt it
|
||||||
if session['is_ai_speaking']:
|
if session['is_ai_speaking']:
|
||||||
session['should_interrupt_ai'] = True
|
session['should_interrupt_ai'] = True
|
||||||
emit('ai_interrupted_by_user', room=session_id)
|
socketio.emit('ai_interrupted_by_user', room=session_id)
|
||||||
|
|
||||||
# Notify client that we detected speech
|
# Notify client that we detected speech
|
||||||
emit('user_speech_start', room=session_id)
|
socketio.emit('user_speech_start', room=session_id)
|
||||||
|
|
||||||
def on_speech_ended(session_id):
|
def on_speech_ended(session_id):
|
||||||
"""Handle end of user speech segment"""
|
"""Handle end of user speech segment"""
|
||||||
@@ -399,12 +399,12 @@ def on_speech_ended(session_id):
|
|||||||
).start()
|
).start()
|
||||||
|
|
||||||
# Notify client that processing has started
|
# Notify client that processing has started
|
||||||
emit('processing_speech', room=session_id)
|
socketio.emit('processing_speech', room=session_id)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error preparing audio: {e}")
|
print(f"Error preparing audio: {e}")
|
||||||
session['is_processing'] = False
|
session['is_processing'] = False
|
||||||
emit('error', {'message': f'Error processing audio: {str(e)}'}, room=session_id)
|
socketio.emit('error', {'message': f'Error processing audio: {str(e)}'}, room=session_id)
|
||||||
|
|
||||||
def process_user_utterance(session_id, audio_path, audio_tensor):
|
def process_user_utterance(session_id, audio_path, audio_tensor):
|
||||||
"""Process user utterance, transcribe and generate response"""
|
"""Process user utterance, transcribe and generate response"""
|
||||||
@@ -427,7 +427,7 @@ def process_user_utterance(session_id, audio_path, audio_tensor):
|
|||||||
|
|
||||||
# Check if we got meaningful text
|
# Check if we got meaningful text
|
||||||
if not user_text or len(user_text.strip()) < 2:
|
if not user_text or len(user_text.strip()) < 2:
|
||||||
emit('no_speech_detected', room=session_id)
|
socketio.emit('no_speech_detected', room=session_id) # CHANGED: emit → socketio.emit
|
||||||
session['is_processing'] = False
|
session['is_processing'] = False
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -448,13 +448,13 @@ def process_user_utterance(session_id, audio_path, audio_tensor):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Send transcription to client
|
# Send transcription to client
|
||||||
emit('transcription', {'text': user_text}, room=session_id)
|
socketio.emit('transcription', {'text': user_text}, room=session_id) # CHANGED: emit → socketio.emit
|
||||||
|
|
||||||
# Generate AI response
|
# Generate AI response
|
||||||
ai_response = generate_ai_response(user_text, session_id)
|
ai_response = generate_ai_response(user_text, session_id)
|
||||||
|
|
||||||
# Send text response to client
|
# Send text response to client
|
||||||
emit('ai_response_text', {'text': ai_response}, room=session_id)
|
socketio.emit('ai_response_text', {'text': ai_response}, room=session_id) # CHANGED: emit → socketio.emit
|
||||||
|
|
||||||
# Update conversation history
|
# Update conversation history
|
||||||
session['conversation_history'].append({
|
session['conversation_history'].append({
|
||||||
@@ -476,7 +476,7 @@ def process_user_utterance(session_id, audio_path, audio_tensor):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error processing utterance: {e}")
|
print(f"Error processing utterance: {e}")
|
||||||
emit('error', {'message': f'Error: {str(e)}'}, room=session_id)
|
socketio.emit('error', {'message': f'Error: {str(e)}'}, room=session_id) # CHANGED: emit → socketio.emit
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# Clear processing flag
|
# Clear processing flag
|
||||||
|
|||||||
Reference in New Issue
Block a user