Needing help with user made vocal commands sent via bluetooth

let me start off by saying I’m new-ish but I have searched forums, google, youtube, etc and I just can’t find what I need to put me on the right path. I have a project where I am using my app to control a Bluetooth relay module. everything I have works great but I am trying to make it where the user can change what they want the word or phrase to be to operate said relay. I have it where I can put in a word for the user to operate but I would like the user to decide his/her own wording. I’m thinking it can be done with tinydb but after days I’m frustrated lol. I will attach pics and my aia, if anyone can help or point me in the right direction thank a million.

basic_controls.aia (2.6 KB)

In the relay codes (maybe Arduino),
Receive 1 = Channel1 ON,
2 = Channel1 OFF,
3 = Channel2 ON,
4 = Channel2 OFF …

In Block of the App, the user will indicate:
on1 —> send 1
off1 ----> send 2

encender1 —> send 1
apagar1 —> send 2

ouvrir un --> send 1
fermer un —> send 2

You need an extra GUI section for programming a table (dictionary) of utterances and codes (A0-D4).
Add a Vertical Arrangement for programming (vaProgramming), and a Program button outside it to switch it visible or invisible.
The programming table could be a dictionary kept under TinyDB tag PROGRAMMING,
with key = spoken command, value = code to send.
{“channel two open” : “B3”,
“channel one open” : “A3”,
“channel three open” : “C3”,
… }

Speak the key command and store the speech output with the selected code into a new key/value pair in the dictionary, and replace it into TinyDB. Don’t be surprised if the speech output is a homonym (too, two, to, 2) of what you said, as long as it matches the next time you speak.

Here is my shot at adding the programming section …
basic_controls_ABG.aia (5.4 KB)

@ABG that is it perfect! let me ask you this is there a way to save that info on another screen then go back to the first screen where I have Bluetooth connected or is that not possible with app inventor. I tried a few times but it seems like the Bluetooth shuts off when I switch screens. Thank you again for the help also is there a direction you can point me in to learn a little more with how you wrote your code. thank you so much again.

BlueTooth loses connections when you switch screens.

People avoid multiple screens by stacking vertical arrangements, only one visible at a time.

Here is some reading for you …

My project collection …

@ABG is there anyway to keep the stored phrases after you exit the app and then re enter the app, where it saves the phrasing so when i open the app next time i dont have to re set up all the phrases (ill be using 8 different commands is why i ask). thank you

I thought I was doing that, saving the phrase dictionary into TinyDB tag PROGRAMMING each time it changed, and loading it on Screen1.Initialize.

Were you not clicking the Save button?

it records and saves it perfect, but when you close out of the app and open the app again those phrases are not still there, they have to be recorded again. I don’t know much about the tinydb system that is what I was trying to read up on, I figured it would be something like that. but everything else is perfect! thank you for everything thus far.

When you click the Program button, does the ListView appear?

(I test using the emulator, so I have no speech recognition or BlueTooth to test against.
I can dust off an Android device to test the voice recognition part, in a while, depending on how well it held its battery charge over the last few weeks.)

I tested on an actual device, and found my blunder.
When I extracted the command list from storage, I forgot to load it to the ListView Elements, so nothing showed on the screen.

Here are the new .aia file and blocks …
basic_controls_ABG.aia (5.3 KB)

refresh_Phrase_ListView

Please forgive my laziness.

no laziness at all man, you have been an incredible help both on ths app and helping educate me thank you so much.

@ABG i have one more thing to ask with help after making a command and storing it and seeing it in the listview is there any way to tap listviewer and delete/clear that command. i have tried for a few hours and i just cant see what im doing wrong though im sure its simple. i have tried the “after picking” block with removing list or removing from the dictionary nothing is seeming to work. just highlights and does nothing or i get an error something to the fact of “attempt to remove item 2 of an empty list” or “The operation delete dictionary pair cannot accept the arguments” ( i made alot of errors so there where quite a few.) any insight is greatly appreciated. thank you

@ABG if you are around i would really appreciate some help with removing the items in the listview as i really have tried all weekend. im sure you are busy but this may be the final step in my project. thank you again for all the help so far. and if i need to make a new post let me know please and i will. thank you for everything so far.


Please export your project and post it here.

Adding a Delete button was easy.
I leave it for you to test, though.

Here’s the new code …

basic_controls_ABG.aia (5.9 KB) when btnDelete Click
refresh_Phrase_ListView

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.