Speech-Refiner

๐ŸŽ™๏ธ Speech-Refiner

image

๐Ÿ“Œ 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.

๐Ÿ› ๏ธ Backend

๐Ÿ–ฅ๏ธ Frontend

๐Ÿ“„ Troubleshooting Audio Recording & CSP Integration in Speech Refiner

  1. โœ… 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.
  2. ๐Ÿšซ 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.
  3. ๐Ÿ“› 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.
  4. ๐Ÿ“ฆ 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>
      
  5. ๐Ÿ›ก๏ธ 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

๐Ÿค 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.