Speech TTS mbrola path; Could not validate any MBROLA voices - wth

edited January 2016 in Library Questions

Dear all,

I am just using TTS - runs fine with p3 and Win 10.

Anyway, I try to run it with mbrola , us1 now

using

    System.setProperty("mbrola.base", "C:/PGR/mbrola/");
    tts = new TTS("mbrola_us1");

but it says

Could not validate any MBROLA voices at

  C:/PGR/mbrola/

Make sure you FULLY specify the path to
the MBROLA directory using the mbrola.base
system property.

The discussion is a little unclear on Nikolaus Gradwohl page

http://www.local-guru.net/blog/2010/06/20/using-mbrola-voices-with-the-processing-ttslib

He says Win doesn't like spaces in paths so I tried to avoid.

But I don't know how to set the java path now.

I think I set the JAVA path now with

 System.setProperty("mbrola.base", "C:/PGR/mbrola/");

Of course I installed all voices (tried us1 and us3 since only us is supported)

and just pasted the unzipped us1-980512 as a folder named us1 into C:/PGR/mbrola/

and I tried a 1000 other things as well....

(and tried C:/PGR/mbrola/ C:/PGR/mbrola C://PGR//mbrola C://PGR//mbrola// also)

Best, Chrisir ;-)

Answers

  • this is my approach now

    still without mbrola

    if mbrola should work (which it doesn't even then) this:

    System.setProperty("mbrola.base", "C:/PGR/mbrola/");
    tts = new TTS("mbrola_us1");
    

    must be in setup imho.

    // demo for speech TTS 
    
    // demonstrates mouse usage with states.
    
    // one 2D array buttons holds all the screen buttons.
    // 2 user names can be entered.  
    
    import guru.ttslib.*;
    
    // speech class 
    Speech speech;  
    
    // states:
    // consts (numbers must be unique)
    final int stateSplashScreen  = 0; // start screen
    final int stateName1         = 1;
    final int stateName2         = 2;
    final int stateGame          = 3;  
    final int stateGameOver      = 4;
    int state  = stateSplashScreen;       // current 
    final int stateMAX = stateGameOver+1; // the max number 
    
    // 2D array of buttons. 
    // First index = state, 2nd index = number of button in that state
    RectButton[][] buttons = new RectButton [stateMAX][3]; 
    
    // for the tool tip text 
    int timeSinceLastMouseMoved=0;
    
    // messages --------------------
    String msgText="";
    float msgX=0;
    float msgY=0;
    boolean msgShow=false;
    int msgFrameCount = 0;
    
    // text field 
    boolean textFieldCursorIsOn = true; // cursor on / off? 
    String enteredText = "";  // temp input text
    
    // player names 
    String namePlayer1 = "";  // results
    String namePlayer2 = "";
    
    // --------------------
    
    // colors
    final color colWhite      = color(255);
    final color colBlack      = color(0);
    final color colDarkGray   = color(111);
    //---
    final color colRed        = color(255, 0, 0);
    final color colGreen      = color(0, 255, 0);
    final color colBlue       = color(0, 0, 255);
    //---
    final color colYellow     = color(244, 244, 44);
    final color colDarkYellow = color(255, 200, 120);
    
    // colors for Buttons 
    final color col1 = #ff0000;
    final color col2 = #ffff00;
    final color col3 = #000000;
    
    
    // -------------------------------------------------
    
    void setup() {
      // init (runs only once)
      size(800, 800);
    
      // speech class
      speech = new Speech();  
    
      // pre-init btns: set all to non-exist
      for (int i = 0; i<stateMAX; i++) {
        for (int i2 = 0; i2<buttons[i].length; i2++) {
          buttons[i][i2] =  new RectButton( 366, 3, 
            66, 70, col1, col2, false, "", "");
        }
      }
    
      // init btns
    
      // -------------
      // stateSplashScreen
      buttons[stateSplashScreen][0] =  new RectButton( 396 + 9, 433, 
        66, 70, col1, col2, true, "Next", "Go on, click me") ;
    
      // -------------
      // state name 1
      buttons[stateName1][0] =  new RectButton( 396 + 9, 433, 
        66, 70, col1, col2, true, "Next", "Go on, click me") ;
    
      // -------------
      // state name 2
      buttons[stateName2][0] =  new RectButton( 396 + 9, 433, 
        66, 70, col1, col2, true, "Next", "Go on, click me") ;
    
      // -------------
      // stateGame
      buttons[stateGame][0] =  new RectButton( 396 + 9, 433, 
        66, 70, col1, col2, true, "Hello", "Say Hello");
    
      buttons[stateGame][1] =  new RectButton( 396 + 9, 533, 
        66, 70, col1, col2, true, "Bye", "Say Bye");
    
      // -------------
      //stateGameOver
      buttons[stateGameOver][0] =  new RectButton( 396 + 9, 433, 
        66, 70, col1, col2, true, "Return", "return to game");
    } // func 
    
    void draw() { 
      // draw() runs on and on 
    
      getDataToDecideIfToolTipText();
    
      switch (state) {
    
      case stateSplashScreen:
        handleStateSplashScreen(); 
        break;
    
      case stateName1: 
        handleStateName1(); 
        break; 
    
      case stateName2: 
        handleStateName2(); 
        break; 
    
      case stateGame: 
        // Game
        handleStateGame();
        break; 
    
      case stateGameOver:
        // GameOver
        handleStateGameOver(); 
        break;
    
      default:
        // error
        println("Error number 939; unknown state : " 
          + state 
          + ". Abort. #######################################");
        exit();
        break;
      } // switch
      //
    } // func 
    
    // ------------------------------------------------
    // functions for states - called from draw() 
    
    void handleStateSplashScreen() {
      background(11);
      fill(244, 3, 3); // red 
      textSize(16);
      text ("Welcome to our GAME!  ", 210, 313);
      speech.speak("Welcome to our GAME ");
      showButtons();
    } // func 
    
    void handleStateName1() {
      background(11);
      fill(244, 3, 3); // red 
      text (" PLAYER 1 please enter your name....\n", 210, 313);
      speech.speak (" PLAYER 1 please enter your name....");
      // draw the rest (the same for both states)
      handleInput();
    } // func 
    
    void handleStateName2() {
      background(11);
      fill(244, 3, 3); // red 
      text ("   PLAYER 2  please enter your name....\n", 210, 313);
      speech.speak ("  PLAYER 2 please enter your name....");
      // draw the rest (the same for both states)
      handleInput();
    } // func 
    
    void handleInput() {
      // draw the rest 
      // (the same for both states) 
      //TextField
      fill(255);
      textSize(18);
      rect(25, 645, 200, 40);
      fill(0);
      text(enteredText+blinkChar(), 25+5, 645+30);
      fill(255, 2, 2, 11);
      toggleTextFieldCursorIsOn(); 
      // btns 
      showButtons();
    }
    
    void handleStateGame() {
      // Game
      background(11);
      fill(colRed); // red
      text (namePlayer1
        + " versus " 
        + namePlayer2
        + " ", 
        17, 19);
    
      fill(colRed); // red 
      text ("This is the Game....\n"
        + "Don't touch the red rectangle...", 
        210, 313);
    
      // this text is slightly modified, it sounds better this way imho  
      speech.speak ("This is the Game."
        +"\n\n"
        +"Dont \n\n touch the \n red rectangle.");
    
      noStroke();
      fill(colRed) ;
      rect(100, 100, 100, 100);
      fill(255, 2, 255) ;
      // rect(300, 100, 100, 100);
    
      if (mouseX > 100 && mouseX < 100 + 100  &&
        mouseY > 100   && mouseY < 100 + 100) {
        // change state
        timeSinceLastMouseMoved = millis();
        speech.resetSpeakOnlyOnce();
        state = stateGameOver;
      }
    
      // btns
      showButtons();
    
      // message ----
      if (msgShow) {
        fill(colWhite);
        text (msgText, msgX, msgY); 
        if ( frameCount > msgFrameCount + 100 )
          msgShow=false;
      }//if
      //
    } // func 
    
    void handleStateGameOver() {
      // Game over / Lost 
      background(255);
      fill(colRed); // red 
      text ("You LOST....  ", 210, 313);
      text ("Hit any key to start Game", 210, 385);
      speech.speak("You Lost. "); 
      showButtons();
    } // func 
    
    // ----------------------------------------
    // input keyboard
    
    void keyPressed() {
    
      switch (state) {
    
      case stateSplashScreen: 
        // splash screen
        // do nothing 
        break; 
    
      case stateName1:
      case stateName2:
        // the same for both names
        // SEE keyTyped() 
        break;
    
      case stateGame: 
        // Game
        // do nothing 
        break; 
    
      case stateGameOver:
        // Game Over
        timeSinceLastMouseMoved = millis();
        state = stateGame; 
        break;
    
      default:
        // error
        println("Error number 1039; unknown state : " 
          + state + ".");
        exit();
        break;
      } // switch
    } // func 
    
    void keyTyped() {
      // correct states? 
      if ( state == stateName1 || state == stateName2) {
        // yes 
        final char k = key;
    
        // quit?
        if (k == CODED)  
          return; // quit function 
    
        final int len = enteredText.length();
    
        if (k == BACKSPACE) {
          // shorten text   
          enteredText = enteredText.substring(0, max(0, len-1));
        } else if (len >= 44) { 
          return; // quit
        } else if (k == ENTER || k == RETURN) {
          // ignore
        } else if (k == TAB & len < 44-3) {
          // ignore 
          // tbox.txt += "    " ;
        } else if (k == DELETE) { 
          enteredText = ""; // reset
        } else if (k >= ' ') {  
          enteredText += str(k); // add this letter
        } // else if
      } // if
    }
    
    // ----------------------------------------
    // input mouse
    
    void mousePressed() {
    
      // reset timer for mouse over tool tip text  
      timeSinceLastMouseMoved = millis();
    
      // loop over all buttons (i) in the current state
      // when you add a new state, this func can stay the same 
      for (int i = 0; i<buttons[state].length; i++) {
        buttons[state][i].update();
        if (buttons[state][i].Exists && buttons[state][i].pressed()) {
          executeButton(state, i);
        }// if
      }//for
    }//func
    
    // ------------------------------------------ 
    // tools
    
    void showButtons() {
      // loop over all buttons (i) in the current state. 
      // When you add a new state, this func can stay the same.  
      for (int i = 0; i<buttons[state].length; i++) {
        buttons[state][i].update();
        buttons[state][i].display();
        buttons[state][i].toolTip();
      } // for
    } // func 
    
    void executeButton(int stateLocal, int btnNumber) {
      // this is the command center for ALL states and ALL buttons : 
      // when you add a new state, you have to add something here.
    
      // First the state is evaluated and then the bottons within that state.
    
      // Let's eval the state: 
      switch(stateLocal) {
    
        // now the states: 
    
      case stateSplashScreen:
        // Splash Screen
        // Let's eval the buttons for state Splash Screen: 
        switch(btnNumber) {
        case 0:
          timeSinceLastMouseMoved = millis();
          // say something
          speech.resetSpeakOnlyOnce(); 
          speech.speakNow("Let's play.");
          // reset
          state=stateName1;  // go on
          speech.resetSpeakOnlyOnce(); 
          break; 
        default:
          // error
          println("Error number 1122; unknown button: " 
            + btnNumber
            + " in state: "
            + state 
            + ". Abort. #######################################");
          exit();
          break;
        } // inner switch
        break; 
    
      case stateName1:
        // only 1 btn
        namePlayer1 = enteredText;
        enteredText="";
        // say thanks
        // speech.resetSpeakOnlyOnce(); 
        speech.speakNow("Thank you");
        speech.speakNow(namePlayer1);
        // reset 
        state=stateName2;   // go on
        speech.resetSpeakOnlyOnce(); 
        break;
    
      case stateName2:
        // only 1 btn
        namePlayer2 = enteredText;
        enteredText="";
        // say thanks
        // speech.resetSpeakOnlyOnce(); 
        speech.speakNow("Thanks");
        speech.speakNow(namePlayer2);
        // reset 
        state=stateGame;   // go on     
        speech.resetSpeakOnlyOnce(); 
        break;
    
      case stateGame:
        // game  
        switch(btnNumber) {
        case 0:
          // say something 
          // speech.resetSpeakOnlyOnce(); 
          speech.speakNow("Hello");
          msgOn("Hello ", 500, height-100);
          break; 
        case 1:
          // say something 
          // speech.resetSpeakOnlyOnce(); 
          speech.speakNow("Bye");
          msgOn("Bye ", 500, height-100);
          break; 
        default:
          // error
          println("Error number 1123; unknown button: " 
            + btnNumber
            + " in state: "
            + state 
            + ". Abort. #######################################");
          exit();
          break;
        } // inner switch
        break;
    
      case stateGameOver:
        // GameOver
        switch(btnNumber) {
        case 0:
          timeSinceLastMouseMoved = millis();
          state=stateGame; 
          speech.resetSpeakOnlyOnce(); 
          break;    
        default:
          // error
          println("Error number 1124; unknown button: " 
            + btnNumber
            + " in state: "
            + state 
            + ". Abort. #######################################");
          exit();
          break;
        } // inner switch
        break;
    
      default:
        // error
        println("Error number 1339; unknown state : " 
          + state 
          + ". Abort. #######################################");
        exit();
        break;
        //------
      }// outer switch
    }//func
    
    // ---------------------------------------------------------------
    // other stuff
    
    void getDataToDecideIfToolTipText() {
      // get some data to decide if it is time to show tool tip text 
      if ((mouseX!=pmouseX) || (mouseY!=pmouseY)) {
        // mouse moved 
        // store time since last mouse moved 
        timeSinceLastMouseMoved = millis();
      }
    }// func
    
    void msgOn(String txt1, int x1, int y1) {
      msgText=txt1;
      msgX=x1;
      msgY=y1;
      msgShow=true;
      msgFrameCount = frameCount;
    }
    
    String blinkChar() {
      // returns a cursor or nothing
      String buffer = (textFieldCursorIsOn) ? "|" : ""; 
      return buffer;
    }
    
    void toggleTextFieldCursorIsOn() {
      // changes textFieldCursorIsOn 
      if (frameCount%30 == 0) {
        textFieldCursorIsOn = !textFieldCursorIsOn;
      }
    } 
    
    // =========================================
    // class RectButton and Button  
    
    class RectButton extends Button {
    
      // constr 
      public RectButton(int ix, int iy, 
        int isizeX, int isizeY, 
        color icolor, 
        color ihighlight, 
        boolean iExist, 
        String iText, 
        String iToolTipText 
        ) {
        x = ix;
        y = iy;
    
        sizeX = isizeX;
        sizeY = isizeY;    
    
        basecolor = icolor;
        highlightcolor = ihighlight;
        currentcolor = basecolor;
        Exists = iExist;
    
        Text = iText;
        ToolTipText = iToolTipText;
      } // constr 
    
      void display() {
        if (Exists) {
          stroke (ButtonStrokeColor); 
          strokeWeight(0); 
          fill(currentcolor, 30);
          rect(x, y, sizeX, sizeY);        
          if (Text != "") {
            //
            fill(0, 102, 153);
            textAlign(CENTER);
            textSize(16) ;
            text(Text, (x + (sizeX / 2.0)), (y + (sizeY / 2.0))+5);
            textAlign(LEFT);
          } // if (Text != "")
        } // if exists
      } // method display
    } // class
    
    class Button {
      int x, y;
      int sizeX;
      int sizeY;  
      color basecolor, highlightcolor;
      color currentcolor;
      boolean Exists  = false;  
      String Text     = "";
      String ToolTipText = ""; 
      //  String Tag = "";
      //  int Tag2 = 0;
      //  int TagMark = 0; 
      color ButtonStrokeColor = color (255, 255, 255);
    
      void update() {
        if (over()) {
          // Mouse over 
          currentcolor = highlightcolor;
        } else {
          // not Mouse over 
          currentcolor = basecolor;
        }
      } // update 
    
      void toolTip() {
        if (over()) {
          if (!ToolTipText.equals("")) {
            if (millis() - timeSinceLastMouseMoved > 1800) {
              fill(colYellow);
              noStroke();
              textSize (12);
              float tw = textWidth(ToolTipText);
              float xLeft = mouseX-(tw/2); 
              float xRight = mouseX-(tw/2) + tw; 
              float xLeftText = mouseX; 
              if (xRight>=width) { 
                xLeft= width-tw-2;
                xLeftText= xLeft + tw/2;
              } 
              if (xLeft< 2) 
              { 
                xLeft=2;
                xLeftText= 2 + tw / 2;
              }
              rect (xLeft, mouseY+32, tw+4, 20);
              textAlign(CENTER);
              fill(0);
              text(ToolTipText, xLeftText, mouseY+44);
              textAlign(LEFT);
              textSize(16);
            } //  if
          } // if
        } // if
      } // func 
    
      boolean pressed() {
        if (over()) {
          return true;
        } else {
          return false;
        }
      }  // pressed; 
    
      boolean over() {
        if (overRect(x, y, sizeX, sizeY) ) {
          return true;
        } else {
          return false;
        }
      } // over 
    
      boolean overRect(int x, int y, 
        int width, int height) {
        if (mouseX >= x && mouseX <= x+width &&
          mouseY >= y && mouseY <= y+height) {
          return true;
        } else {
          return false;
        }
      } // overRect
      //
    } // class
    
    class Speech {
    
      // speech: this tells for each state whether it's the first time. 
      // Once the speech is triggered we set firstTime to false. 
      // When starting a new state (changing state) we reset firstTime to true again.
      // using the command firstTime=true; . This happens mainly in func mousePressed() or so. 
      int firstTime=0; 
    
      // the lib 
      TTS tts;
    
      // constr
      Speech() {
        // constr
        ///System.setProperty("mbrola.base", "/path/to/mbrola");
        // System.setProperty("mbrola.base", "C://PGR//MbrolaTools");
        // the lib 
        tts = new TTS();
      } // constr 
    
      void speak(String text1) {
        if (firstTime==1) {
          tts.speak(text1);
          //firstTime=false;
          firstTime++;
        } else 
        firstTime++;
      } // method
    
      void speakNow(String text1) {
        //  if (firstTime==0) {
        tts.speak(text1);
        //firstTime=false;
        // firstTime++;
        // }
        // else 
        //firstTime++;
      } // method
    
      void resetSpeakOnlyOnce() {
        firstTime=0;
      } // method
    } // class
    // 
    
Sign In or Register to comment.