Speak Text from file

Lupus52

Member
Hello, I use the German version of MD and I don't find any way to speak single textlines from a file.

For example, 1 have 10 files, numbered from 1.txt to 10.txt.

When special macro is triggered, I want to speak text 5.txt for example. Only 1 line of Ascii

Or alternatively, line 5 from text.txt with 10 lines Ascii

Is there any easy way?
 

Jacob L

Moderator (Lawsonator)
Use shell script to read the file into a string variable.

Shell script is cat /storage/emulated/0/text.txt

Once you've got it into the variable you need to split it. You can use the text manipulation to split to array using a delimiter. Once you have the array you can set the speak text action to array_name[0].

Then you just add a variable to give you the index, for example if you wanted to randomise the line or just increment by 1
 

Lupus52

Member
Sorry - I don't understand anything. Very bad soundquality and not understandable hightech programmerspeaking.
I am a normal user with german language. I can only translate websitetext via google.
 

Jacob L

Moderator (Lawsonator)
Thank you for insulting my videos. I hasn't spotted that you're a German user so on sorry. See the attachment for a macro that does what you want it to.

Put the .txt file in /storage/emulated/0/MacroDroid
 

Attachments

  • test.txt
    75 bytes · Views: 5
  • Read_line_by_line.macro
    4.9 KB · Views: 5

Dm114

Well-known member
Hello, I use the German version of MD and I don't find any way to speak single textlines from a file.

For example, 1 have 10 files, numbered from 1.txt to 10.txt.

When special macro is triggered, I want to speak text 5.txt for example. Only 1 line of Ascii

Or alternatively, line 5 from text.txt with 10 lines Ascii

Is there any easy way?
If you have 10 files it's even much simpler. Just read the file whose content (line to speak) will be stored in a string variable. Then use Speak Text action and that's it!
 

Lupus52

Member
Thank you for insulting my videos. I hasn't spotted that you're a German user so on sorry. See the attachment for a macro that does what you want it to.

Put the .txt file in /storage/emulated/0/MacroDroid
Thank you very much - I will try it tomorrow. First I must learn how to get your macro into my macrodroids macro list
 

Lupus52

Member
If you have 10 files it's even much simpler. Just read the file whose content (line to speak) will be stored in a string variable. Then use Speak Text action and that's it!
This is what I want. Reading the filecontent in a variable. But I don't know how!
 

Endercraft

Moderator (& bug finder :D)
Files --> read from file then select your file using either static filename (can only read this one) or dynamic filename (read any file which you can specify with magic text in a specific directory).
 

Lupus52

Member
Files --> read from file then select your file using either static filename (can only read this one) or dynamic filename (read any file which you can specify with magic text in a specific directory).
Sorry, I don't understand anything! I am NO programmer - only a simple user. I use MD since some years with the given commands. And I did not find any things about you all tell me to do. I have downloaded the macro and testfile from "Jacob L" The macro works 1 time. I see the local variables and the text from the testfile in the array. It works 1 one time and needs many minutes until the answer is spoken. I tried many times - no answers. And 10 Minutes later a lot of them. There is a delay and a cache? And my phone gets slower and slower. I had to restart now many times. I seams, that the file is read only one time. I have replaced the testcontent to what I want to use, but there stays always the old testcontent in the variables. The only thing that works is the changing of the random number after calling the macro. Is there any documentation elsewhere with explanation for an stupid beginner to start?
 

Lupus52

Member
Just use the Read From File action.
Ok - "action" found. Thank you. :) And now?

Situation:

Bluetooth-remotecontrol triggers my macro.
Depending on "<" or ">" a variable n is incremented or decremented. (1<->10)
Textline n is to be spoken.

Therefore, I need to have the content of the file in an array. Line by line.

text (1) =
text (2) =
text (3) =
a.s.o.
text(10) =

Now I need a command that the text(n) is to be spoken

To work I need to declare variables? Text-action to speak element from arrayelement a.s.o.
 

Dm114

Well-known member
Ok - "action" found. Thank you. :) And now?

Situation:

Bluetooth-remotecontrol triggers my macro.
Depending on "<" or ">" a variable n is incremented or decremented. (1<->10)
Textline n is to be spoken.

Therefore, I need to have the content of the file in an array. Line by line.

text (1) =
text (2) =
text (3) =
a.s.o.
text(10) =

Now I need a command that the text(n) is to be spoken

To work I need to declare variables? Text-action to speak element from arrayelement a.s.o.
If you have several files you need not use Array. You can read whatever file you want (maybe randomly) every time you need to.
 

Lupus52

Member
If you have several files you need not use Array. You can read whatever file you want (maybe randomly) every time you need to.
Hello, I have it running now like I want. With one File of 10 lines of text and array is the easiest way.

Thank you to all.
 

Dm114

Well-known member
Hello, I have it running now like I want. With one File of 10 lines of text and array is the easiest way.

Thank you to all.
Congratulations!

This is the "nicest" way but not the easiest. It's the reason why I was leading you to the simplest way (several files -as you told it was what you had at the beginning- instead of a unique file converted to an Array).

I would suggest you to read MD Wiki to get more familiar with MacroDroid and become able to write your macros by your own, even if we all still will be there to help you.
 

Lupus52

Member
Congratulations!

This is the "nicest" way but not the easiest. It's the reason why I was leading you to the simplest way (several files -as you told it was what you had at the beginning- instead of a unique file converted to an Array).

I would suggest you to read MD Wiki to get more familiar with MacroDroid and become able to write your macros by your own, even if we all still will be there to help you.
Thank you. I know the WIKI. But I don't like it. :-( - It may be good for a professional. But not really usable for beginners with MD. I am missing a real good tutorial with explanations and examples since I know MD.

Now my job works. I read 15 lines of the file in an array. Then I read the line with the actually wanted line number word by word in a second array. These words then are spoken in a loop all one after the other with a little delay between.

The cause for this project: I don't want to work with a paper trainingplan in fitness. Therefore, I first used an Excel-table on my phone. But the handling is annoying.

Now I use a little Bluetooth remotecontrol (smartwatch) to increment/decrement trainingplacenumbers. Via earphone, I then get the number, local place in the room and name of the training machine with the values to adjust like seat place, weight and so on. The text file is generated and changed from the Excel-file via an Excel-macro direct via google-drive in my phone.
 
Top