Package javax.speech.synthesis

Examples of javax.speech.synthesis.Synthesizer


                "general",     // mode name
                Locale.US,     // locale
                null,          // running
                null);         // voice
           
      final Synthesizer synthesizer1 =
                Central.createSynthesizer(generalDesc);

      if (synthesizer1 == null) {
    System.err.println(
                    noSynthesizerMessage("general domain synthesizer"));
    System.exit(1);
      }

      /* Find a synthesizer that has the time domain voice.
             */
      SynthesizerModeDesc limitedDesc = new SynthesizerModeDesc(
                null,          // engine name
                "time",        // mode name
                Locale.US,     // locale
                null,          // running
                null);         // voice

      final Synthesizer synthesizer2 =
                Central.createSynthesizer(limitedDesc);

      if (synthesizer2 == null) {
    System.err.println(
                    noSynthesizerMessage("time domain synthesizer"));
    System.exit(1);
      }

      System.out.print("  Allocating synthesizers...");
      synthesizer1.allocate();
      synthesizer2.allocate();

      /* get general domain synthesizer ready to speak
             */
      System.out.print("Loading voices...");
      synthesizer1.getSynthesizerProperties().setVoice(kevinHQ);
      synthesizer1.getSynthesizerProperties().setVoice(kevin);

      if (showPropertyChanges) {
    synthesizer1.getSynthesizerProperties().addPropertyChangeListener(
                    new PropertyChangeListener() {
                        public void propertyChange(
                            PropertyChangeEvent pce) {
                            if (pce.getNewValue() instanceof Voice) {
        String newVoice =
            ((Voice) pce.getNewValue()).getName();
        System.out.println(
                                    "  PCE Voice changed to " + newVoice);
          } else {
        System.out.println(
                                    "  PCE " + pce.getPropertyName()
                                    + " changed from "
            + pce.getOldValue() + " to " +
            pce.getNewValue() + ".");
          }
      }
        });
      }
           
      if (showEvents) {
    synthesizer1.addSpeakableListener(
        new SpeakableAdapter() {
      public void markerReached(SpeakableEvent e) {
          dumpEvent(e);
      }
      public void speakableCancelled(SpeakableEvent e) {
          dumpEvent(e);
      }
      public void speakableEnded(SpeakableEvent e) {
          dumpEvent(e);
      }
      public void speakablePaused(SpeakableEvent e) {
          dumpEvent(e);
      }
      public void speakableResumed(SpeakableEvent e) {
          dumpEvent(e);
      }
      public void speakableStarted(SpeakableEvent e) {
          dumpEvent(e);
      }
      public void topOfQueue(SpeakableEvent e) {
          dumpEvent(e);
      }
      public void wordStarted(SpeakableEvent e) {
          dumpEvent(e);
      }
      private void dumpEvent(SpeakableEvent e) {
          System.out.println(" EVT: " + e.paramString()
                                               + " source: " + e.getSource());
      }
        });
      }
     
      System.out.println("And here we go!");
      synthesizer1.resume();
      synthesizer2.resume();
     
      // speak the "Hello world" string
      synthesizer1.speakPlainText("Hello! My name is Kevin.", null);
      synthesizer1.speakPlainText("I am a die phone synthesizer", null);
      synthesizer1.speakPlainText("I have a friend named Alan.", null);
      synthesizer1.speakPlainText("Listen to him count!", null);

      // get synth2 ready to speak
      synthesizer2.waitEngineState(Synthesizer.ALLOCATED);
      synthesizer2.resume();

      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);
      synthesizer2.speakPlainText("1 2 3 4 5 6 7 8 9 ten", null);

      synthesizer2.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.speakPlainText("Now listen to me count!", null);
      synthesizer1.speakPlainText("1 2 3 4 5 6 7 8 9 10.", null);

      synthesizer1.speakPlainText(
        "Now, let's try that a little bit faster.", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.getSynthesizerProperties().setSpeakingRate(240.0f);
      synthesizer1.speakPlainText("1 2 3 4 5 6 7 8 9 10.", null);
      synthesizer1.speakPlainText("That's pretty fast.", null);
      synthesizer1.speakPlainText("Now lets go very slow.", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.getSynthesizerProperties().setSpeakingRate(80.0f);
      synthesizer1.speakPlainText("1 2 3 4 5 6 7 8 9 10.", null);
      synthesizer1.speakPlainText("That is pretty slow.", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.getSynthesizerProperties().setSpeakingRate(150.0f);
      synthesizer1.speakPlainText("Now back to normal", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.getSynthesizerProperties().setPitch(200);
      synthesizer1.speakPlainText("I can talk very high.", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.getSynthesizerProperties().setPitch(50);
      synthesizer1.speakPlainText("and I can talk very low.", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.getSynthesizerProperties().setPitch(100);
      synthesizer1.getSynthesizerProperties().setVolume(.8f);
      synthesizer1.speakPlainText("and I can talk very softly.", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.getSynthesizerProperties().setVolume(1.0f);
      synthesizer1.speakPlainText(
    "I can talk with a higher quality voice", null);
      synthesizer1.speakPlainText(
        "Here is a low quality tongue twister. "
        + "She sells seashells by the seashore.", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.getSynthesizerProperties().setVoice(kevinHQ);
      synthesizer1.speakPlainText("And this is high quality. "
        + "She sells seashells by the seashore.", null);
      synthesizer1.speakPlainText(
        "The funny thing is, I do not have a tongue.", null);
      synthesizer1.speakPlainText(
    "Hey Alan, what time is it where you are right now?", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer2.speakPlainText(
        "the time is now twenty past six.", null);
      synthesizer2.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.speakPlainText("Is that the exact time?", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer2.speakPlainText("Almost", null);
      synthesizer2.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.speakPlainText(
    "Is it twenty past six In the morning or the evening?", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer2.speakPlainText("in the morning.", null);
      synthesizer2.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.speakPlainText(
        "Alan and I can talk at the same time", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.speakPlainText("1 2 3 4 5 6 7 8 9 11 12", null);
      synthesizer2.speakPlainText("1 2 3 4 5 6 7 8 9", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);
      synthesizer2.waitEngineState(Synthesizer.QUEUE_EMPTY);

      synthesizer1.speakPlainText( "That is a bit confusing.", null);
      synthesizer1.speakPlainText( "Well, thanks. This was fun.", null);
      synthesizer1.speakPlainText("Goodbye everyone.", null);
      synthesizer1.waitEngineState(Synthesizer.QUEUE_EMPTY);
     
      // clean up
      synthesizer1.deallocate();
      synthesizer2.deallocate();
  }
  catch (Exception e) {
      e.printStackTrace();
  }

View Full Code Here


    /**
     * Close this playable
     */
    public void close() {
  for (Iterator i = loadedSynthesizers.iterator(); i.hasNext();) {
      Synthesizer synth = (Synthesizer) i.next();
      try {
    synth.deallocate();
      } catch (EngineException ee) {
    System.out.println("Trouble closing the synthesizer: " + ee);
      }
  }
    }
View Full Code Here

            queueEmptyLabel.setEnabled(
                engine.testEngineState(Synthesizer.QUEUE_EMPTY));
            queueNotEmptyLabel.setEnabled(
                engine.testEngineState(Synthesizer.QUEUE_NOT_EMPTY));

      Synthesizer synth = (Synthesizer) engine;
      int queueSize = countElements(synth.enumerateQueue());
      queueSizeLabel.setText("Queue Size: " + queueSize + "  ");
        }
    }
View Full Code Here

        try {
            System.setProperty("freetts.voices",
                    "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");

            Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
            Synthesizer synthesizer =
                    Central.createSynthesizer(new SynthesizerModeDesc(Locale.US));
            synthesizer.allocate();
            synthesizer.resume();
            synthesizer.speakPlainText("Can you hear me now?", null);
            synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
            synthesizer.deallocate();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

          System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
          Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
 
          SynthesizerModeDesc desc = new SynthesizerModeDesc(null, "general", Locale.US, null, null);
 
          Synthesizer synth = Central.createSynthesizer(desc);
          synth.allocate();
          desc = (SynthesizerModeDesc) synth.getEngineModeDesc();
          Voice[] voices = desc.getVoices();
          Voice voice = null;
          for (Voice entry : voices) {
              if(entry.getName().equals(voiceName)) {
                  voice = entry;
                  break;
              }
          }
          synth.getSynthesizerProperties().setVoice(voice);
          synth.resume();
          synth.speakPlainText(text, null);
          synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
          synth.deallocate();
 
      } catch(Exception ex) {
          String message = " missing speech.properties in " + System.getProperty("user.home") + "\n";
          System.out.println("" + ex);
          System.out.println(message);
View Full Code Here

    public static void main(String args[]) {
        // 利用 FreeTTS 读出Good job
        try {
            SynthesizerModeDesc desc = new SynthesizerModeDesc("FreeTTS en_US general synthesizer", "general",
                    Locale.US, null, null);
            Synthesizer synthesizer = Central.createSynthesizer(desc);
            if (synthesizer == null) {
                System.exit(1);
            }
            synthesizer.allocate();
            synthesizer.resume();
            desc = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
            Voice voices[] = desc.getVoices();
            for (Voice v : voices) {
                synthesizer.getSynthesizerProperties().setVoice(v);
                synthesizer.speakPlainText("good job", null);
                synthesizer.waitEngineState(0x10000L);
            }
            synthesizer.deallocate();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
View Full Code Here

     * Close this playable
     */
    public void close() {
  //deallocate all synthesizer
        for (Iterator i = loadedSynthesizers.iterator(); i.hasNext();) {
      Synthesizer synth = (Synthesizer) i.next();
      try {
    synth.deallocate();
      } catch (EngineException ee) {
    System.out.println("Trouble closing the synthesizer: " + ee);
      }
  }
    }
View Full Code Here

TOP

Related Classes of javax.speech.synthesis.Synthesizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.