How to pause a Nuance session The Next CEO of Stack OverflowHow do I efficiently iterate over each entry in a Java Map?How do save an Android Activity state using save instance state?How do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?Why is the Android emulator so slow? How can we speed up the Android emulator?How do servlets work? Instantiation, sessions, shared variables and multithreadingHow do I convert a String to an int in Java?How do I fix android.os.NetworkOnMainThreadException?

Why didn't Khan get resurrected in the Genesis Explosion?

sp_blitzCache results Memory grants

What can we do to stop prior company from asking us questions?

Why has the US not been more assertive in confronting Russia in recent years?

Is there a way to save my career from absolute disaster?

How to invert MapIndexed on a ragged structure? How to construct a tree from rules?

Is it professional to write unrelated content in an almost-empty email?

"In the right combination" vs "with the right combination"?

Make solar eclipses exceedingly rare, but still have new moons

Should I tutor a student who I know has cheated on their homework?

Is there a difference between "Fahrstuhl" and "Aufzug"

What does convergence in distribution "in the Gromov–Hausdorff" sense mean?

How to count occurrences of text in a file?

Why am I allowed to create multiple unique pointers from a single object?

Which kind of appliances can one connect to electric sockets located in an airplane's toilet?

Is it ever safe to open a suspicious html file (e.g. email attachment)?

How to prevent changing the value of variable?

Why does standard notation not preserve intervals (visually)

What happens if you roll doubles 3 times then land on "Go to jail?"

What connection does MS Office have to Netscape Navigator?

Why do professional authors make "consistency" mistakes? And how to avoid them?

Why do we use the plural of movies in this phrase "We went to the movies last night."?

Received an invoice from my ex-employer billing me for training; how to handle?

Is it my responsibility to learn a new technology in my own time my employer wants to implement?



How to pause a Nuance session



The Next CEO of Stack OverflowHow do I efficiently iterate over each entry in a Java Map?How do save an Android Activity state using save instance state?How do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?Why is the Android emulator so slow? How can we speed up the Android emulator?How do servlets work? Instantiation, sessions, shared variables and multithreadingHow do I convert a String to an int in Java?How do I fix android.os.NetworkOnMainThreadException?










0















i'm working on an app that uses Nuance tts sdk.



In the main activity my app will play an audio file through calling the synthesize method in another class. When the user leave the main activity i want to stop the session (sound) but i can't figure out how to do this



From my main activity i call the method in the class



 illustrate.startSynthesize();


my class that implement the SDK :



 package com.example.illuminate_me;

import android.content.Context;

import com.nuance.speechkit.Audio;
import com.nuance.speechkit.AudioPlayer;
import com.nuance.speechkit.Language;
import com.nuance.speechkit.Session;
import com.nuance.speechkit.Transaction;
import com.nuance.speechkit.TransactionException;
import com.nuance.speechkit.Voice;

public class Illustrate implements AudioPlayer.Listener
private Session speechSession;
private Transaction ttsTransaction;
private Illustrate.State state = Illustrate.State.IDLE;
private String voice ="Tarik";
private Context context;
private String text;


public Illustrate(String tts, Context context)
this.context=context;
this.text=tts;

//Create a session
speechSession = Session.Factory.session(context, Configuration.SERVER_URI, Configuration.APP_KEY);
speechSession.getAudioPlayer().setListener(this);

setState(Illustrate.State.IDLE);
// startSynthesize();


public void startSynthesize()
toggleTTS();



private void toggleTTS()
switch (state)
case IDLE:
if(ttsTransaction == null)
synthesize();

//Otherwise lets attempt to cancel that transaction
else
cancel();

break;
case PLAYING:
speechSession.getAudioPlayer().pause();
setState(Illustrate.State.PAUSED);
break;
case PAUSED:
speechSession.getAudioPlayer().play();
setState(Illustrate.State.PLAYING);
break;



public void synthesize()
//Setup our TTS transaction options.
Transaction.Options options = new Transaction.Options();
options.setLanguage(new Language(Configuration.LANGUAGE));

options.setVoice(new Voice(voice));
ttsTransaction = speechSession.speakString(text, options, new Transaction.Listener()
@Override
public void onAudio(Transaction transaction, Audio audio)

ttsTransaction = null;


@Override
public void onSuccess(Transaction transaction, String s)



@Override
public void onError(Transaction transaction, String s, TransactionException e)

ttsTransaction = null;

);



/**
* Cancel the TTS transaction.
* This will only cancel if we have not received the audio from the server yet.
*/
private void cancel()
ttsTransaction.cancel();


@Override
public void onBeginPlaying(AudioPlayer audioPlayer, Audio audio)

setState(Illustrate.State.PLAYING);


@Override
public void onFinishedPlaying(AudioPlayer audioPlayer, Audio audio)
setState(Illustrate.State.IDLE);





private enum State
IDLE,
PLAYING,
PAUSED


/**
* Set the state and update the button text.
*/
private void setState(Illustrate.State newState)
state = newState;
switch (newState)
case IDLE:
// Next possible action is speaking
break;
case PLAYING:
// Next possible action is pausing
break;
case PAUSED:
// Next possible action is resuming the speech
// toggleTTS.setText(getResources().getString(R.string.speak_string));
break;





Any help is very much appreciated.
This is the documentation if any one want to take a look at it
Speech synthesis (TTS)










share|improve this question


























    0















    i'm working on an app that uses Nuance tts sdk.



    In the main activity my app will play an audio file through calling the synthesize method in another class. When the user leave the main activity i want to stop the session (sound) but i can't figure out how to do this



    From my main activity i call the method in the class



     illustrate.startSynthesize();


    my class that implement the SDK :



     package com.example.illuminate_me;

    import android.content.Context;

    import com.nuance.speechkit.Audio;
    import com.nuance.speechkit.AudioPlayer;
    import com.nuance.speechkit.Language;
    import com.nuance.speechkit.Session;
    import com.nuance.speechkit.Transaction;
    import com.nuance.speechkit.TransactionException;
    import com.nuance.speechkit.Voice;

    public class Illustrate implements AudioPlayer.Listener
    private Session speechSession;
    private Transaction ttsTransaction;
    private Illustrate.State state = Illustrate.State.IDLE;
    private String voice ="Tarik";
    private Context context;
    private String text;


    public Illustrate(String tts, Context context)
    this.context=context;
    this.text=tts;

    //Create a session
    speechSession = Session.Factory.session(context, Configuration.SERVER_URI, Configuration.APP_KEY);
    speechSession.getAudioPlayer().setListener(this);

    setState(Illustrate.State.IDLE);
    // startSynthesize();


    public void startSynthesize()
    toggleTTS();



    private void toggleTTS()
    switch (state)
    case IDLE:
    if(ttsTransaction == null)
    synthesize();

    //Otherwise lets attempt to cancel that transaction
    else
    cancel();

    break;
    case PLAYING:
    speechSession.getAudioPlayer().pause();
    setState(Illustrate.State.PAUSED);
    break;
    case PAUSED:
    speechSession.getAudioPlayer().play();
    setState(Illustrate.State.PLAYING);
    break;



    public void synthesize()
    //Setup our TTS transaction options.
    Transaction.Options options = new Transaction.Options();
    options.setLanguage(new Language(Configuration.LANGUAGE));

    options.setVoice(new Voice(voice));
    ttsTransaction = speechSession.speakString(text, options, new Transaction.Listener()
    @Override
    public void onAudio(Transaction transaction, Audio audio)

    ttsTransaction = null;


    @Override
    public void onSuccess(Transaction transaction, String s)



    @Override
    public void onError(Transaction transaction, String s, TransactionException e)

    ttsTransaction = null;

    );



    /**
    * Cancel the TTS transaction.
    * This will only cancel if we have not received the audio from the server yet.
    */
    private void cancel()
    ttsTransaction.cancel();


    @Override
    public void onBeginPlaying(AudioPlayer audioPlayer, Audio audio)

    setState(Illustrate.State.PLAYING);


    @Override
    public void onFinishedPlaying(AudioPlayer audioPlayer, Audio audio)
    setState(Illustrate.State.IDLE);





    private enum State
    IDLE,
    PLAYING,
    PAUSED


    /**
    * Set the state and update the button text.
    */
    private void setState(Illustrate.State newState)
    state = newState;
    switch (newState)
    case IDLE:
    // Next possible action is speaking
    break;
    case PLAYING:
    // Next possible action is pausing
    break;
    case PAUSED:
    // Next possible action is resuming the speech
    // toggleTTS.setText(getResources().getString(R.string.speak_string));
    break;





    Any help is very much appreciated.
    This is the documentation if any one want to take a look at it
    Speech synthesis (TTS)










    share|improve this question
























      0












      0








      0








      i'm working on an app that uses Nuance tts sdk.



      In the main activity my app will play an audio file through calling the synthesize method in another class. When the user leave the main activity i want to stop the session (sound) but i can't figure out how to do this



      From my main activity i call the method in the class



       illustrate.startSynthesize();


      my class that implement the SDK :



       package com.example.illuminate_me;

      import android.content.Context;

      import com.nuance.speechkit.Audio;
      import com.nuance.speechkit.AudioPlayer;
      import com.nuance.speechkit.Language;
      import com.nuance.speechkit.Session;
      import com.nuance.speechkit.Transaction;
      import com.nuance.speechkit.TransactionException;
      import com.nuance.speechkit.Voice;

      public class Illustrate implements AudioPlayer.Listener
      private Session speechSession;
      private Transaction ttsTransaction;
      private Illustrate.State state = Illustrate.State.IDLE;
      private String voice ="Tarik";
      private Context context;
      private String text;


      public Illustrate(String tts, Context context)
      this.context=context;
      this.text=tts;

      //Create a session
      speechSession = Session.Factory.session(context, Configuration.SERVER_URI, Configuration.APP_KEY);
      speechSession.getAudioPlayer().setListener(this);

      setState(Illustrate.State.IDLE);
      // startSynthesize();


      public void startSynthesize()
      toggleTTS();



      private void toggleTTS()
      switch (state)
      case IDLE:
      if(ttsTransaction == null)
      synthesize();

      //Otherwise lets attempt to cancel that transaction
      else
      cancel();

      break;
      case PLAYING:
      speechSession.getAudioPlayer().pause();
      setState(Illustrate.State.PAUSED);
      break;
      case PAUSED:
      speechSession.getAudioPlayer().play();
      setState(Illustrate.State.PLAYING);
      break;



      public void synthesize()
      //Setup our TTS transaction options.
      Transaction.Options options = new Transaction.Options();
      options.setLanguage(new Language(Configuration.LANGUAGE));

      options.setVoice(new Voice(voice));
      ttsTransaction = speechSession.speakString(text, options, new Transaction.Listener()
      @Override
      public void onAudio(Transaction transaction, Audio audio)

      ttsTransaction = null;


      @Override
      public void onSuccess(Transaction transaction, String s)



      @Override
      public void onError(Transaction transaction, String s, TransactionException e)

      ttsTransaction = null;

      );



      /**
      * Cancel the TTS transaction.
      * This will only cancel if we have not received the audio from the server yet.
      */
      private void cancel()
      ttsTransaction.cancel();


      @Override
      public void onBeginPlaying(AudioPlayer audioPlayer, Audio audio)

      setState(Illustrate.State.PLAYING);


      @Override
      public void onFinishedPlaying(AudioPlayer audioPlayer, Audio audio)
      setState(Illustrate.State.IDLE);





      private enum State
      IDLE,
      PLAYING,
      PAUSED


      /**
      * Set the state and update the button text.
      */
      private void setState(Illustrate.State newState)
      state = newState;
      switch (newState)
      case IDLE:
      // Next possible action is speaking
      break;
      case PLAYING:
      // Next possible action is pausing
      break;
      case PAUSED:
      // Next possible action is resuming the speech
      // toggleTTS.setText(getResources().getString(R.string.speak_string));
      break;





      Any help is very much appreciated.
      This is the documentation if any one want to take a look at it
      Speech synthesis (TTS)










      share|improve this question














      i'm working on an app that uses Nuance tts sdk.



      In the main activity my app will play an audio file through calling the synthesize method in another class. When the user leave the main activity i want to stop the session (sound) but i can't figure out how to do this



      From my main activity i call the method in the class



       illustrate.startSynthesize();


      my class that implement the SDK :



       package com.example.illuminate_me;

      import android.content.Context;

      import com.nuance.speechkit.Audio;
      import com.nuance.speechkit.AudioPlayer;
      import com.nuance.speechkit.Language;
      import com.nuance.speechkit.Session;
      import com.nuance.speechkit.Transaction;
      import com.nuance.speechkit.TransactionException;
      import com.nuance.speechkit.Voice;

      public class Illustrate implements AudioPlayer.Listener
      private Session speechSession;
      private Transaction ttsTransaction;
      private Illustrate.State state = Illustrate.State.IDLE;
      private String voice ="Tarik";
      private Context context;
      private String text;


      public Illustrate(String tts, Context context)
      this.context=context;
      this.text=tts;

      //Create a session
      speechSession = Session.Factory.session(context, Configuration.SERVER_URI, Configuration.APP_KEY);
      speechSession.getAudioPlayer().setListener(this);

      setState(Illustrate.State.IDLE);
      // startSynthesize();


      public void startSynthesize()
      toggleTTS();



      private void toggleTTS()
      switch (state)
      case IDLE:
      if(ttsTransaction == null)
      synthesize();

      //Otherwise lets attempt to cancel that transaction
      else
      cancel();

      break;
      case PLAYING:
      speechSession.getAudioPlayer().pause();
      setState(Illustrate.State.PAUSED);
      break;
      case PAUSED:
      speechSession.getAudioPlayer().play();
      setState(Illustrate.State.PLAYING);
      break;



      public void synthesize()
      //Setup our TTS transaction options.
      Transaction.Options options = new Transaction.Options();
      options.setLanguage(new Language(Configuration.LANGUAGE));

      options.setVoice(new Voice(voice));
      ttsTransaction = speechSession.speakString(text, options, new Transaction.Listener()
      @Override
      public void onAudio(Transaction transaction, Audio audio)

      ttsTransaction = null;


      @Override
      public void onSuccess(Transaction transaction, String s)



      @Override
      public void onError(Transaction transaction, String s, TransactionException e)

      ttsTransaction = null;

      );



      /**
      * Cancel the TTS transaction.
      * This will only cancel if we have not received the audio from the server yet.
      */
      private void cancel()
      ttsTransaction.cancel();


      @Override
      public void onBeginPlaying(AudioPlayer audioPlayer, Audio audio)

      setState(Illustrate.State.PLAYING);


      @Override
      public void onFinishedPlaying(AudioPlayer audioPlayer, Audio audio)
      setState(Illustrate.State.IDLE);





      private enum State
      IDLE,
      PLAYING,
      PAUSED


      /**
      * Set the state and update the button text.
      */
      private void setState(Illustrate.State newState)
      state = newState;
      switch (newState)
      case IDLE:
      // Next possible action is speaking
      break;
      case PLAYING:
      // Next possible action is pausing
      break;
      case PAUSED:
      // Next possible action is resuming the speech
      // toggleTTS.setText(getResources().getString(R.string.speak_string));
      break;





      Any help is very much appreciated.
      This is the documentation if any one want to take a look at it
      Speech synthesis (TTS)







      java android nuance






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 14:35









      Lulu ASLulu AS

      11




      11






















          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55065373%2fhow-to-pause-a-nuance-session%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55065373%2fhow-to-pause-a-nuance-session%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived