mbi / django-simple-captcha

Django Simple Captcha is an extremely simple, yet highly customizable Django application to add captcha images to any Django form.
http://django-simple-captcha.readthedocs.io/en/latest/
MIT License
1.37k stars 319 forks source link

Play Audio From Captcha In Browser Not From .wav File. #178

Open 9mido opened 4 years ago

9mido commented 4 years ago

This is a feature request. In addition to being able to click on a captcha image and download a .wav file of the captcha (since some people might like this), there should be an additional way to change this default behavior - to listen to the audio by doing something like clicking an audio play button in the browser web page to directly hear the captcha text without downloading it. Or maybe leave both options or choose one or the other for downloading the .wav file and playing in the browser.

One additional feature for the audio that would be nice is to have some more options for the audio playback that might sound better. Flite is okay, but it doesn't sound that great especially with sox brown noise rainbow table protection. Using alternatives that sound like Google Text To Speech or others would be nice (but GTTS requires an API / internet connection which might be problematic). It would probably be best to not use any third party text to audio programs to accomplish this. The whole reason I am using this project is to avoid cookies and to be GDPR / Cookie Law Compliant. If nothing other than Flite could be used, it is not a big deal. I am more concerned with being able to play the audio in the browser.

If neither of these features are possible, can someone so kindly provide some code below to be able to accomplish one or both of these things universally to work anywhere (regular template forms, allauth forms, etc.)

A main reason for requesting this is to be compliant with ADA laws.

SilverStrings024 commented 4 years ago

Please let me know if anyone would like some help coding this. I did this for myself and would like to help make the project even better!

mbi commented 4 years ago

@SilverStrings024 pull requests are always welcome! :bowing_man:

SilverStrings024 commented 4 years ago

@SilverStrings024 pull requests are always welcome! bowing_man

I'm not sure what branch to do this to. I've never done a pull request so I'll need to read into it and see if I can use the existing code so it is automatically rendered instead of needing to be rendered after the page loads because currently it's just taking the existing captcha, breaking it apart and implanting an audio player to the browser after the document is ready.

9mido commented 4 years ago

@mbi Take a look at code written by SilverStrings024. It did not work when he tried to help me with it (we still need to do a remote session together) but maybe it can give you some ideas of how to do implement a feature like this since I had trouble trying to implement it in my project.

https://pastebin.com/hXAzVbcv

9mido commented 4 years ago

Update: I was able to accomplish playing the audio in the browser using https://django-simple-captcha.readthedocs.io/en/latest/advanced.html#rendering and adding

<audio controls>
  <source src="{{ audio }}" />
</audio>

to custom_field.html

https://stackoverflow.com/questions/18972515/how-to-create-ajax-refresh-for-django-simple-captcha