๐๏ธ Speech-Refiner

๐ Overview
Speech Refiner is an Electron-based desktop application that allows users to record their voice or upload .wav
audio files, and refine the tone of speech using a polite transformation API (hosted separately). The application is built using modern web technologies and packaged for desktop use via Electron.
๐ฅ๏ธ Frontend
-
๐ Features
- ๐ค In-App Audio Recording via microphone (saved in proper
.wav
format)
- ๐ File Upload option for
.wav
files
- ๐ Playback Support with ability to review recorded or uploaded audio
- โก One-Click API Call to refine speech
- ๐ Modern UI built with Bootstrap 5, supports dark mode and drag & drop
- ๐ฆ Electron Desktop Packaging (cross-platform-ready)
-
๐งฉ Tech Stack
- Frontend Framework: Vanilla HTML, CSS, JavaScript
- UI Library: Bootstrap 5
- Recording Engine:
recorder.js
(local patched version - with more explanation below in troubleshooting section)
- Electron: For packaging the app as a desktop .exe
- External API: Abstracted polite speech transformation engine
- ๐๏ธ Directory Structure
โโโ index.html # Main UI
โโโ recorder.js # Local patched WAV recorder script
โโโ favicon.ico # App icon
โโโ main.js # Electron main process
- ๐ฎ Usage Flow
- Record Audio
- Click the โRecordโ button to start capturing audio from your microphone.
- Press โStopโ to end recording. The audio will auto-play and show duration.
- Or Upload File
- Use the file picker or drag-and-drop a
.wav
file into the interface.
- Download
- Optionally download your recording using the built-in playback control.
- ๐ฆ Packaging for Distribution
- To run the app, run:
- To build the
.exe
:
npm install
npx electron-packager . SpeechRefiner --platform=win32 --arch=x64 --icon=favicon.ico --overwrite
This will create a packaged version of the app using Electron Packager or Electron Forge (as configured).
- โ๏ธ Notes
- Microphone access must be allowed when prompted.
- The API endpoint is abstracted and not included in the public repository. (Users can request for the API)
- Replace the placeholder API URL with the required API when using.
- ๐ก๏ธ Security
- This version is intended for local/private use:
- No sensitive data is stored or shared.
- Content Security Policy (CSP) is not enforced to preserve dev flexibility.
- The
.exe
is not recommended for public distribution with embedded API keys.
๐ Troubleshooting Audio Recording & CSP Integration in Speech Refiner
- โ
Local API vs Hosted API Issues
- Issue: Hosted API (
http://192.168.x.x:5000
) didnโt respond as expected inside Electron.
- Cause: Hosted API had longer response time (~5 sec) with no visual feedback.
- Fixes:
- Added a
Processing...
loader during API call.
- Verified API response behavior using Postman/browser.
- ๐ซ Unsupported Audio Format (WebM instead of WAV)
- Error:
File format b'\x1aE\xdf\xa3' not understood. Only 'RIFF' and 'RIFX' supported.
- Cause: MediaRecorder API defaulted to WebM; Flask expected
.wav
.
- Fix: Switched to
recorder.js
which generates proper .wav
output.
- ๐ Invalid WAV Header (nAvgBytesPerSec mismatch)
- Error:
WAV header is invalid: nAvgBytesPerSec must equal product of nSamplesPerSec and nBlockAlign
- Cause: Some versions of Recorder.js generated incorrect headers.
- Fixes:
- CDN failed due to MIME issues.
- Forked versions had broken links.
- Manually downloaded corrected
recorder.js
from GitHub and loaded it locally.
- ๐ฆ MIME Type Execution Errors
- Error:
Refused to execute script from CDN because its MIME type was 'text/plain'
- Fix: Used local version of recorder.js:
<script src="recorder.js"></script>
- ๐ก๏ธ Electron Warning
- Message:
Insecure Content-Security-Policy: no CSP or unsafe-eval used
- Strict CSP Attempt
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; connect-src http://192.168.x.x:5000;">
- Issue:
- Inline scripts blocked.
- Microphone stopped.
- API hit prematurely without file.
- Root Cause
- Electron apps commonly use inline scripts or libraries requiring relaxed policies.
- Strict CSP blocks
eval
, inline JavaScript, dynamic execution.
- Solutions Attempted
- Tried relaxed CSP with:
script-src 'self' 'unsafe-inline'
- Inline scripts worked, but reintroduced security risks (e.g., XSS).
- Final Decision
- โ CSP not applied now due to dev-time constraints.
- โ
Plan:
- Keep .exe private.
- Share code with API placeholder.
- Let users build locally and request API key if needed.
recorder.js
is downloaded from here.
๐งญ Recommendations for Future Deployment
- Extract all inline scripts into external files.
- Set a strict and secure CSP header.
- Remove unsafe-inline and unsafe-eval.
- Validate microphone permissions and backend headers for production use.
๐ค Contributing
Contributions are welcome! Please fork the repository and submit a pull request for any enhancements or bug fixes. For more details and updates, visit the GitHub Repository.