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

          Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

          Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

          How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page