tts

from flask import Flask, render_template, request, send_file, jsonify from pydub import AudioSegment import os app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') @app.route('/process', methods=['POST']) def process_audio(): if 'audio_file' not in request.files: return jsonify({'error': 'No file provided'}) audio_file = request.files['audio_file'] if audio_file.filename == '': return jsonify({'error': 'No file selected'}) try: # Save the uploaded file temporarily temp_path = 'temp_input.wav' audio_file.save(temp_path) # Process the audio file audio = AudioSegment.from_wav(temp_path) female_audio = audio.set_frame_rate(44100 * 2) # Double the frame rate # Save the modified audio temporarily temp_output_path = 'temp_output.wav' female_audio.export(temp_output_path, format="wav") # Send the modified audio as a response return send_file(temp_output_path, as_attachment=True, download_name="modified_audio.wav") except Exception as e: # Log the error for debugging print(f"Error processing audio: {str(e)}") return jsonify({'error': 'Error processing audio. Please try again.'}) finally: # Cleanup: Remove temporary files if os.path.exists(temp_path): os.remove(temp_path) if os.path.exists(temp_output_path): os.remove(temp_output_path) if __name__ == '__main__': app.run(debug=True)

Post a Comment

0 Comments