Implement Voice to Text feature using Jetpack Compose - Android

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so everyone today we are going to create a voice to text parser in Android using jetpack compose so let's start by creating our voice to text parser voice to text parser that will inherit the record recognition listener and let's implement the functions option enter on Mac and I think it's Alt Enter on Windows Let's uh select all of these and let's also create two functions that we'll use later start listening that will have a language called and that will be a string and um Cass um stop listening listen oops I guess now we need to create our voice to text parser state so let's create it down here data class Voice to Text state or let's add parser state and now let's add spoken text this will be a string is speaking this will be a Boolean employer default is false and the error in case we encounter some errors now let's create our state so we'll private wall state incores metable state flow of voice so text parser state and now we can create the state that will be a state flow and now let's create the recognizer recognizer that will be a speech recognizer that creates PC recognizer and now we need to pass the app so let's add it into the Constructor privatewal app application and now let's add this here let's start by implementing the store listening so we need to clear the state first The Voice to Text parser state and now we can check you the speech recognition is available and let's engage this and if it's not available let's um show an error it's a DOT copy error um with a recognition is not available now let's create the intent that will perform the voice to text so recognizer intent to actually recognize speech dot apply and now let's put some extra arguments intent oh oops recognizer intent extra language model and now we add recognizer intent free model form so this will be a free speech not a search speech also we need to specify the language um recognize recognizer intent extra language um language code now let's set the recognition listener [Music] so the commission listener and it will build mbds now let's start listening so recognizer start listening and we pass the intents from both now we also need to update the state so it will say that speaking is true and now let's start by implementing the stop listening and this will be a simple function date dot update it dot copy the speaking is false and the recognizer will be dot stop listening already first page it will clear the errors so into that copy error equals node the on beginning of speech we don't need this so it will be a unit we don't need this tool this will be on unit 2 because we don't need it earn it and on end of speech we say say that updates um it's load copy is speaking false front end of speech we just say that is speaking is false on our function we check if the error is client error so speech recognizer error client and if it's on our client we return otherwise we update the state with the error so um error equals error and we display the error code our results we just returned the spoken text so results and get Stringer released speech recognizer results recognition we get the first results get or no and we um check if the results aren't in all and let's update the state state DOT update it's dot copy the spoken text is done on results result and we don't need the own partial results and the on event and let's assign your need for them now let's go to the build.gradle and paste this dependency this will give us the microphone icon and let's sing the project now we can go into the Manifest and add the uses permission to record audio and now let's close this and go to the main activity now let's create our voice to text parser so Voice to Text parser equals not equals by lazy and oops voice.text parser application and we are using valency because this will wait until the application is available to create the voice of text parser now let's create our floor can record this will be a buy remember oops remember state of false and that's important to these now let's create the record audio launcher launcher this will be a remember activity launcher activity for result and the contracts will be launch activity result contracts that request permission and it will have our result is granted and we are signed a carry code with it now let's have a large defect block launch effect block and the key is the record audio launcher and let's say chordaudio launcher dot launch and let's say the Manifest from the Android permission and record audio now we can start to create the scaffold and get the padding from it and assign the padding to the padding modifier from the column so modifier Dot padding the padding from the scaffold let's say filmex sites before and add some 20 DB padding and let's import the DP um Also let's obtain for the scaffold and let's say vertical Arrangement Arrangement Dot Center and horizontal alignment alignment Dot Center vertically how horizontally sorry now we can create an animated content in this will animate the content whenever it changes the state changes and let's get the states so state by our voice to text parser State collect as state and now we can access the speaking and let's option for this tool around the main activity is speaking and let's check if he's speaking is speaking we want to display Dot a text that shows oops speaking Dot and um as we want to show the state DOT spoken text and if it's empty we want to say um re click on mic to record audio and now we can create the floating action button so Floating Action button will be a floating action button of course and let's implement the on click function if say that is speaking we want to stop the speaking of the listening so Voice to Text parsers stop listening otherwise we want to start listening so start listening and the default code is English let's create an animated content block inside the of The Floating Action button so state that it is picking and we get this picking and if it's picking we want to display an icon on icons.rounded dot stop so we want to display the stop icon if he's speaking otherwise let's copy this and paste and change the icon to mic and I think everything is okay and let's run the app and see how it looks so we need to press while using the app and let's record the audio this is a test as you can see it works perfectly and if you like this video follow me for more content like this and I also have a Blog on which I post weekly so make sure to follow me on it too [Music]
Info
Channel: Daniel Atitienei
Views: 2,270
Rating: undefined out of 5
Keywords: Jetpack Compose, Kotlin, Android
Id: jyXf1WS-wI8
Channel Id: undefined
Length: 11min 30sec (690 seconds)
Published: Fri Mar 10 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.