Implementing Speech To Text on a field #15745
-
PackageForm builder Package Versionv3.3 How can we help you?I would like to know if anyone have implemented a speech to text api with a simple TextInput or Textarea field? In short I have a project where I need to be able to populate a field from speech. This will be used at a dance festival, as part of the judging, where the judges' comments needs to be recorded and transcribed for the dancer's final report. The easiest would obviously be to use such an api, and directly record the comments, have it transcribed in near real-time and saved. I have attempted a few guides, including the "x-webkit-speech" attribute on the field (this did not work - it appears to be deprecated); also to run javascript on the input's suffix action (also did not work - the "onresult" never fired): Ideally the field should have a button to start/stop the listening, as the above "continuous = false" part stops as soon as the person takes a breath (not ideal for the judge's comments;). In the above I just do not have an extra button to use to stop the listening, and making another livewire request just to once again get/execute some js is not practical. Have anyone implemented something like this? Any help greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Ok, after many hours working at this, I actually have something that works for the most part. That was until I found a browser extension that allows this on any field, without needing all of this custom code. I am still posting the code, as a reference for anyone that needs to do it in their project (without being able to control the browser where it will be used from). The first file is a Custom Form Field, extending the default TextInput (so that everything related to it, will still work; can just as well extend the textarea): SpeechToTextInput.php This file is meant to overwrite the Next I copied the standard field's view, but only modified a couple of lines (speech-to-text-input.blade.php): I added the Now for the javascript part. Since I already imported Alpine into my 'app.js' file (for plugins to use), I can simply add the alpine component into this file, before the This code simply setups the component, getting the id for the field that should receive the text. It created a couple of internal properties to keep track of everything and then define the method that will be called when the button is clicked/pressed. If the listener is running, we will stop the recognition service, and set the color of the icon to green, before returning. Otherwise we check if we already have a recognition service, and set it up if we don't have it (it will alert you if your browser does not support it). The settings for the recognition service can be adjusted as needed (continuous, InterimResults, language etc). It also setup the even handler for a result - in my case it simply replace the existing content with the result ( Once the js is compiled, with for example vite, you can then add the Note that currently this is tested in Google Chrome and works. Firefox does not work, and many others probably do not work - it uses the Google api/service. It also requires internet (thus not usable in an intranet/offline capacity). |
Beta Was this translation helpful? Give feedback.
Ok, after many hours working at this, I actually have something that works for the most part. That was until I found a browser extension that allows this on any field, without needing all of this custom code. I am still posting the code, as a reference for anyone that needs to do it in their project (without being able to control the browser where it will be used from).
The first file is a Custom Form Field, extending the default TextInput (so that everything related to it, will still work; can just as well extend the textarea): SpeechToTextInput.php