Creating an advanced voice/meeting recorder web application involves both backend and frontend development. Below is a comprehensive guide to building such an application using Python with Flask for the backend and HTML, CSS, and JavaScript for the frontend. We'll use SQLite as the database for simplicity, and SQLAlchemy as the ORM.
Project Overview
-
Features:
- Recording Tab:
- Start/Stop recording
- Select audio source: Microphone, Desktop Audio, or Both
- Add title at the beginning or end
- Take timestamped notes
- Mark important segments
- Add custom segments to the timeline
- Recorded Meetings Tab:
- List of recorded meetings
- Play audio files
- View segments and notes
- Display recording time range
-
Technologies Used:
- Backend: Python, Flask, SQLAlchemy
- Frontend: HTML, CSS, JavaScript (with MediaRecorder API)
- Database: SQLite
Project Structure
voice_recorder/
├── app.py
├── models.py
├── requirements.txt
├── static/
│ ├── css/
│ │ └── styles.css
│ └── js/
│ └── recorder.js
├── templates/
│ ├── index.html
│ └── recordings.html
└── recordings/
Step-by-Step Implementation
1. Setup the Flask Application
First, set up a virtual environment and install the required packages.
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
# Install dependencies
pip install Flask SQLAlchemy Flask-Migrate
Create a requirements.txt for future reference:
Flask
SQLAlchemy
Flask-Migrate
2. Define the Database Models
Create a models.py file to define the database schema using SQLAlchemy.
# models.py
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
db = SQLAlchemy()
class Recording(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(150), nullable=False)
filename = db.Column(db.String(200), nullable=False)
start_time = db.Column(db.DateTime, default=datetime.utcnow)
end_time = db.Column(db.DateTime)
notes = db.relationship('Note', backref='recording', lazy=True)
segments = db.relationship('Segment', backref='recording', lazy=True)
class Note(db.Model):
id = db.Column(db.Integer, primary_key=True)
timestamp = db.Column(db.Float, nullable=False)
content = db.Column(db.Text, nullable=False)
recording_id = db.Column(db.Integer, db.ForeignKey('recording.id'), nullable=False)
class Segment(db.Model):
id = db.Column(db.Integer, primary_key=True)
type = db.Column(db.String(50), nullable=False) # e.g., "important", "custom"
timestamp = db.Column(db.Float, nullable=False)
description = db.Column(db.String(200))
recording_id = db.Column(db.Integer, db.ForeignKey('recording.id'), nullable=False)
3. Initialize the Flask App
Create app.py to set up the Flask application, database, and routes.
# app.py
import os
from flask import Flask, render_template, request, redirect, url_for, jsonify
from models import db, Recording, Note, Segment
from datetime import datetime
from werkzeug.utils import secure_filename
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///recordings.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['UPLOAD_FOLDER'] = 'recordings'
db.init_app(app)
# Ensure the upload folder exists
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
@app.before_first_request
def create_tables():
db.create_all()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/save_recording', methods=['POST'])
def save_recording():
data = request.json
title = data.get('title', 'Untitled Recording')
filename = data.get('filename')
start_time = datetime.fromisoformat(data.get('start_time'))
end_time = datetime.fromisoformat(data.get('end_time'))
notes = data.get('notes', [])
segments = data.get('segments', [])
recording = Recording(
title=title,
filename=filename,
start_time=start_time,
end_time=end_time
)
db.session.add(recording)
db.session.commit()
for note in notes:
new_note = Note(
timestamp=note['timestamp'],
content=note['content'],
recording_id=recording.id
)
db.session.add(new_note)
for segment in segments:
new_segment = Segment(
type=segment['type'],
timestamp=segment['timestamp'],
description=segment.get('description', ''),
recording_id=recording.id
)
db.session.add(new_segment)
db.session.commit()
return jsonify({'status': 'success'}), 200
@app.route('/recordings')
def recordings():
all_recordings = Recording.query.order_by(Recording.start_time.desc()).all()
return render_template('recordings.html', recordings=all_recordings)
@app.route('/recordings/<int:recording_id>')
def recording_detail(recording_id):
recording = Recording.query.get_or_404(recording_id)
return render_template('recording_detail.html', recording=recording)
if __name__ == '__main__':
app.run(debug=True)
4. Create Frontend Templates
a. index.html
This is the main page where users can record meetings.
<!-- templates/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Advanced Voice Recorder</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
</head>
<body>
<h1>Advanced Voice/Meeting Recorder</h1>
<div class="tabs">
<button class="tablink" onclick="openTab(event, 'Record')">Record</button>
<button class="tablink" onclick="openTab(event, 'OldRecordings')">Old Recordings</button>
</div>
<div id="Record" class="tabcontent">
<h2>Record a Meeting</h2>
<input type="text" id="title" placeholder="Enter Title">
<div>
<label for="audioSource">Select Audio Source:</label>
<select id="audioSource">
<option value="both" selected>Both</option>
<option value="microphone">Microphone</option>
<option value="desktop">Desktop Audio</option>
</select>
</div>
<button id="startBtn">Start Recording</button>
<button id="stopBtn" disabled>Stop Recording</button>
<h3>Notes</h3>
<textarea id="notes" placeholder="Take notes here..."></textarea>
<h3>Segments</h3>
<button onclick="addSegment('important')">Mark Important</button>
<input type="text" id="customSegment" placeholder="Custom Segment Description">
<button onclick="addCustomSegment()">Add Custom Segment</button>
<h3>Recording Timeline</h3>
<ul id="segmentsList"></ul>
</div>
<div id="OldRecordings" class="tabcontent">
<h2>Old Recordings</h2>
<a href="{{ url_for('recordings') }}">View All Recordings</a>
</div>
<script src="{{ url_for('static', filename='js/recorder.js') }}"></script>
</body>
</html>
b. recordings.html
This page lists all recorded meetings.
<!-- templates/recordings.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Recorded Meetings</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
</head>
<body>
<h1>Recorded Meetings</h1>
<a href="{{ url_for('index') }}">Back to Record</a>
<ul>
{% for recording in recordings %}
<li>
<h3>{{ recording.title }}</h3>
<p>Recorded from {{ recording.start_time.strftime('%H:%M') }} to {{ recording.end_time.strftime('%H:%M') }}</p>
<audio controls>
<source src="{{ url_for('static', filename='recordings/' + recording.filename) }}" type="audio/webm">
Your browser does not support the audio element.
</audio>
<h4>Notes:</h4>
<ul>
{% for note in recording.notes %}
<li>[{{ note.timestamp | round(2) }}s] {{ note.content }}</li>
{% endfor %}
</ul>
<h4>Segments:</h4>
<ul>
{% for segment in recording.segments %}
<li>{{ segment.type.capitalize() }} at {{ segment.timestamp | round(2) }}s - {{ segment.description }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</body>
</html>
c. recording_detail.html (Optional)
For detailed view of a single recording.
<!-- templates/recording_detail.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ recording.title }}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
</head>
<body>
<h1>{{ recording.title }}</h1>
<a href="{{ url_for('recordings') }}">Back to All Recordings</a>
<p>Recorded from {{ recording.start_time.strftime('%H:%M') }} to {{ recording.end_time.strftime('%H:%M') }}</p>
<audio controls>
<source src="{{ url_for('static', filename='recordings/' + recording.filename) }}" type="audio/webm">
Your browser does not support the audio element.
</audio>
<h2>Notes</h2>
<ul>
{% for note in recording.notes %}
<li>[{{ note.timestamp | round(2) }}s] {{ note.content }}</li>
{% endfor %}
</ul>
<h2>Segments</h2>
<ul>
{% for segment in recording.segments %}
<li>{{ segment.type.capitalize() }} at {{ segment.timestamp | round(2) }}s - {{ segment.description }}</li>
{% endfor %}
</ul>
</body>
</html>
5. Implement Frontend Functionality with JavaScript
Create recorder.js in static/js/ to handle recording, notes, and segments.
// static/js/recorder.js
let mediaRecorder;
let recordedChunks = [];
let startTime;
let notes = [];
let segments = [];
let segmentList = document.getElementById('segmentsList');
// Initialize MediaRecorder
async function initRecorder() {
const audioSource = document.getElementById('audioSource').value;
let constraints = {};
if (audioSource === 'microphone') {
constraints = { audio: true };
} else if (audioSource === 'desktop') {
constraints = { audio: { echoCancellation: false } };
// Note: Capturing desktop audio may require additional setup and permissions
} else {
constraints = { audio: true };
// Combining both is complex and may require multiple streams
}
const stream = await navigator.mediaDevices.getUserMedia(constraints);
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.ondataavailable = handleDataAvailable;
mediaRecorder.onstop = handleStop;
}
function handleDataAvailable(event) {
if (event.data.size > 0) {
recordedChunks.push(event.data);
}
}
function handleStop(event) {
const blob = new Blob(recordedChunks, { type: 'audio/webm' });
const filename = `${Date.now()}.webm`;
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
// Upload the recording to the server
uploadRecording(blob, filename);
}
async function uploadRecording(blob, filename) {
const formData = new FormData();
formData.append('file', blob, filename);
// Additional data like title, notes, segments can be sent here
// For simplicity, this example only uploads the file
const response = await fetch('/save_recording', {
method: 'POST',
body: JSON.stringify({
title: document.getElementById('title').value,
filename: filename,
start_time: startTime.toISOString(),
end_time: new Date().toISOString(),
notes: notes,
segments: segments
}),
headers: {
'Content-Type': 'application/json'
}
});
if (response.ok) {
alert('Recording saved successfully!');
// Reset variables
recordedChunks = [];
notes = [];
segments = [];
segmentList.innerHTML = '';
} else {
alert('Failed to save recording.');
}
}
document.getElementById('startBtn').addEventListener('click', async () => {
await initRecorder();
mediaRecorder.start();
startTime = new Date();
document.getElementById('startBtn').disabled = true;
document.getElementById('stopBtn').disabled = false;
});
document.getElementById('stopBtn').addEventListener('click', () => {
mediaRecorder.stop();
document.getElementById('startBtn').disabled = false;
document.getElementById('stopBtn').disabled = true;
});
// Functions to add notes and segments
document.getElementById('notes').addEventListener('input', (e) => {
// Implement real-time note saving with timestamps if needed
});
function addSegment(type) {
const timestamp = getCurrentTimestamp();
const segment = { type: type, timestamp: timestamp, description: '' };
segments.push(segment);
displaySegment(segment);
}
function addCustomSegment() {
const description = document.getElementById('customSegment').value;
if (description.trim() === '') return;
const timestamp = getCurrentTimestamp();
const segment = { type: 'custom', timestamp: timestamp, description: description };
segments.push(segment);
displaySegment(segment);
document.getElementById('customSegment').value = '';
}
function displaySegment(segment) {
const li = document.createElement('li');
li.textContent = `${segment.type.toUpperCase()} at ${segment.timestamp.toFixed(2)}s - ${segment.description}`;
segmentList.appendChild(li);
}
function getCurrentTimestamp() {
if (!startTime) return 0;
return (Date.now() - startTime.getTime()) / 1000;
}
Notes:
-
Capturing Desktop Audio: Capturing desktop audio directly via the browser can be challenging due to browser security restrictions. It often requires using the Screen Capture API with specific permissions. Additionally, not all browsers support capturing system audio. For comprehensive desktop audio capture, consider building a desktop application or using browser extensions.
-
Uploading Records: The JavaScript in this example uploads the recording as soon as it's stopped. Depending on your requirements, you might want to implement more sophisticated upload and processing mechanisms.
-
Real-time Notes: Implementing real-time timestamped notes would require synchronizing user inputs with the recording timeline. This can be achieved using periodic checks or event listeners tied to the playback or recording state.
-
Security Considerations: Ensure that file uploads are secured to prevent malicious files from being uploaded. Validate and sanitize all inputs on the server side.
6. Styling the Application
Create a styles.css file in static/css/ to style the application.
/* static/css/styles.css */
body {
font-family: Arial, sans-serif;
margin: 20px;
}
h1, h2, h3, h4 {
color: #333;
}
.tabs {
margin-bottom: 20px;
}
.tablink {
background-color: #f1f1f1;
border: none;
padding: 10px 20px;
cursor: pointer;
margin-right: 5px;
}
.tablink:hover {
background-color: #ddd;
}
.tabcontent {
display: none;
}
#segmentsList {
list-style-type: none;
padding: 0;
}
7. Running the Application
Ensure all components are in place and run the Flask application.
export FLASK_APP=app.py
export FLASK_ENV=development
flask run
Navigate to http://localhost:5000 in your browser to access the application.
Final Remarks
This guide provides a foundational framework for an advanced voice/meeting recorder web application. Depending on specific requirements, you might need to enhance functionalities such as:
- User Authentication: Implement user login and registration if you want to associate recordings with specific users.
- Audio Processing: Convert audio files to different formats, transcribe audio to text, etc.
- Enhanced UI/UX: Improve the frontend with better design and user interactions using frameworks like React or Vue.js.
- Scalability: Use a more robust database system and storage solutions for handling large numbers of recordings.
Feel free to expand upon this foundation to tailor the application to your specific needs!