1

Ok this may have been asked before but I can not find a definite answer.

I am building an app for my Father, who wants a bible app. It's going to be using speech recognition. I can create the whole app, with No problems, I am just trying to figure out if there is an easier way.

I have a txt file with Genesis chapter 1, and then I have several txt files that is Genesis chapter one, but each txt file is one verse.

I can call each txt file and read it no problem. However if I do it this way, there is going to be several thousand txt files, and several thousand lines of code.

I know the file is read by chunks. Is there a way I can take the entire chapter and read one line, for example:

    If (speech == "Genesis chapter one verse nine")
       {
            Bible.SpeakAsync(@"Gen1V9.txt");
       }

I know the index would be 0 - X. With x signifying the length of the text. The I could call the nth line

      If (speech == "Genesis chapter one verse nine")
         {
                 Bible.SpeakAsync(File.ReadLine[10](@"Gen1.txt");
         }

I have omitted a lot of code, however this is an example. Instead of me calling each txt file, can I call one txt file and have it read a certain line. If so the entire Bible would be a fixed length, so I would know that verse 9 will always be line 10 in the txt file.

This how i have done it for years, by pulling individual txt files, but I am wanting to clean up the code and use minimal code as possible.

I hope this makes sense. The speech is irrelevant, I am just needing to find a solution to get the nth line.

Source is http://www.sacred-texts.com/bib/osrc/

Halonic
  • 405
  • 2
  • 12
  • 1
    Possible duplicate of [How do I read a specified line in a text file?](https://stackoverflow.com/questions/1262965/how-do-i-read-a-specified-line-in-a-text-file) – mjwills Jun 14 '18 at 13:03
  • How do you know it is line 10? If you have a lookup to 10 then why not just have a lookup to the actual text? – paparazzo Jun 14 '18 at 13:27
  • Index always starts with 0. So 0 = 1 (first line). Now I could have 32,000 plus txt files, which would slow the application and use a lot of RAM. Having just one text file it is less code instead of pulling each txt file for the verse that would average out for the entire Bible over 210,000 lines of code. Only having one text and read the line cuts that down to about 70,000 lines of code. – Halonic Jun 14 '18 at 13:35

1 Answers1

1

You can use File.ReadAllLines():

string[] bible = File.ReadAllLines("path-to-text-file.txt");
 Bible.SpeakAsync (bible[0]); //line one
 Bible.SpeakAsync (bible[1]); //line two

To make it speak multiple lines (9-10-11)...: You may do it like:

 Bible.SpeakAsync(bible[9]+bible[10]);

Or you can have a function like:

void Speak(params int[] lines)
{
    string all = "";
    for(int i=0; i< lines.length; i++)
    all += bible[lines[i]];
    Bible.SpeakAsync(all);
}

and then you can use it like:

Speak(10);
Speak(9,10,11,12);
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
  • Ok, so that was my idea, however when I expand it out to the entire Bible in one txt file, then each chapter in a text file. Can I read multiple lines? Like Bible.SpeakAsync(bible[1]) && (bible[9]); so it would read line 1 then line 9 – Halonic Jun 14 '18 at 13:08
  • Bible.SpeakAsync(bible[9]+bible[10]); – Ashkan Mobayen Khiabani Jun 14 '18 at 13:09
  • Also when I get done with my morning coffee I am going to test it. If works good then I will mark it as answered. – Halonic Jun 14 '18 at 13:11
  • @Mobayen I see that it's shows how to read multiple lines. It just did not register as I read it. – Halonic Jun 14 '18 at 13:13
  • I did, when I wrote the comment that part was not there. – Halonic Jun 14 '18 at 13:15
  • I think having a function like `Speak` in my answer, would be nice that can speak, one or multiple rows – Ashkan Mobayen Khiabani Jun 14 '18 at 13:16
  • I am going to try it then if everything goes well, then it's on to the cross reference with a concordance implementation. – Halonic Jun 14 '18 at 13:17
  • Well I build speech applications, and I tried the free dictation and I was having some problems. Along the same lines. My father wants it to read the bible to him and he writes his thoughts. He would love to have it to where it reads then as he speaks out loud it keeps track of his thoughts and cross references it with other verses and locations of the bible. So example, If he says where all is Love mentioned, then I will just have to find the lines and have it put in a list box. – Halonic Jun 14 '18 at 13:21