Complete Refactor 2
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
from flask import Flask
|
||||
from flask_socketio import SocketIO
|
||||
from src.utils.config import Config
|
||||
from src.utils.logger import setup_logger
|
||||
from api.routes import setup_routes
|
||||
from api.socket_handlers import setup_socket_handlers
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
|
||||
setup_logger(app)
|
||||
setup_routes(app)
|
||||
setup_socket_handlers(app)
|
||||
|
||||
return app
|
||||
|
||||
app = create_app()
|
||||
socketio = SocketIO(app)
|
||||
|
||||
if __name__ == "__main__":
|
||||
socketio.run(app, host='0.0.0.0', port=5000)
|
||||
@@ -1,29 +0,0 @@
|
||||
from flask import Blueprint, request, jsonify
|
||||
from src.services.transcription_service import TranscriptionService
|
||||
from src.services.tts_service import TextToSpeechService
|
||||
|
||||
api = Blueprint('api', __name__)
|
||||
|
||||
transcription_service = TranscriptionService()
|
||||
tts_service = TextToSpeechService()
|
||||
|
||||
@api.route('/transcribe', methods=['POST'])
|
||||
def transcribe_audio():
|
||||
audio_data = request.files.get('audio')
|
||||
if not audio_data:
|
||||
return jsonify({'error': 'No audio file provided'}), 400
|
||||
|
||||
text = transcription_service.transcribe(audio_data)
|
||||
return jsonify({'transcription': text})
|
||||
|
||||
@api.route('/generate-response', methods=['POST'])
|
||||
def generate_response():
|
||||
data = request.json
|
||||
user_input = data.get('input')
|
||||
if not user_input:
|
||||
return jsonify({'error': 'No input provided'}), 400
|
||||
|
||||
response_text = tts_service.generate_response(user_input)
|
||||
audio_data = tts_service.text_to_speech(response_text)
|
||||
|
||||
return jsonify({'response': response_text, 'audio': audio_data})
|
||||
@@ -1,32 +0,0 @@
|
||||
from flask import request
|
||||
from flask_socketio import SocketIO, emit
|
||||
from src.audio.processor import process_audio
|
||||
from src.services.transcription_service import TranscriptionService
|
||||
from src.services.tts_service import TextToSpeechService
|
||||
from src.llm.generator import load_csm_1b
|
||||
|
||||
socketio = SocketIO()
|
||||
|
||||
transcription_service = TranscriptionService()
|
||||
tts_service = TextToSpeechService()
|
||||
generator = load_csm_1b()
|
||||
|
||||
@socketio.on('audio_stream')
|
||||
def handle_audio_stream(data):
|
||||
audio_data = data['audio']
|
||||
speaker_id = data['speaker']
|
||||
|
||||
# Process the incoming audio
|
||||
processed_audio = process_audio(audio_data)
|
||||
|
||||
# Transcribe the audio to text
|
||||
transcription = transcription_service.transcribe(processed_audio)
|
||||
|
||||
# Generate a response using the LLM
|
||||
response_text = generator.generate(text=transcription, speaker=speaker_id)
|
||||
|
||||
# Convert the response text back to audio
|
||||
response_audio = tts_service.convert_text_to_speech(response_text)
|
||||
|
||||
# Emit the response audio back to the client
|
||||
emit('audio_response', {'audio': response_audio, 'speaker': speaker_id})
|
||||
Reference in New Issue
Block a user