How to see if word exists in Pocketsphinx dictionary?

前端 未结 3 1898
醉酒成梦
醉酒成梦 2021-01-22 18:40

I simply want to see if a string exists in a dictionary file. (Dictionary file at bottom of question)

I want to check if the voice recognizer can recogn

3条回答
  •  清歌不尽
    2021-01-22 19:12

    Read the file using BufferedReader and store all the words in ArrayList

    ArrayList dictionary = new ArrayList<>();
    String line;
    BufferedReader reader = new BufferedReader(new FileReader(dictionaryFile));
    while((line = reader.readLine()) != null) {
        if(line.trim().length() <= 0 ) {
            continue;
        }
        String word = line.split(" ")[0].trim();
        word = word.replaceAll("[^a-zA-Z]", "");
        dictionary.add(word);
    }
    

    then check if word present in dictionary using

    dictionary.contains(yourString);
    

    Hope it'll help.

提交回复
热议问题