starting a text to speech engine in background

Put your problem here if it does not fit any of the other categories.

starting a text to speech engine in background

Postby streetfi8er » Fri Jun 25, 2010 3:45 pm

i am trying to start the tts engine through a service but am unable to do so, is it that the tts cannot be started from a service and needs an Activity to do so?

here's what i have tried:
Code: Select all
public void onCreate(){
      Log.d("SpeakerService","Service created successfully!");
      mtts = new TextToSpeech(getApplicationContext(),this);
      
      
   }
   @Override
   public void onStart(Intent intent,int startid)
   {
      Log.d("SpeakerService","Service started successfully!");
   
      mtts = new TextToSpeech(getApplicationContext(),this);
      mtts.setLanguage(Locale.ENGLISH);
      Log.d("SmsSpeaker3","created mtts successfully");
      mtts.speak("Testing",TextToSpeech.QUEUE_FLUSH, null);
      Log.d("Speaker","synthesis done successfully");
   }



in the log i am getting the statement "synthesis done successfully" but am not getting any sound
streetfi8er
Junior Developer
Junior Developer
 
Posts: 15
Joined: Sat Jun 12, 2010 1:03 am

Top

Re: starting a text to speech engine in background

Postby Benzebuth » Fri Jun 25, 2010 7:04 pm

i don't know much about it. But don't you have to decalre something in your Manifest file, for your activity to be able to launch the text-to-speech one
Image
User avatar
Benzebuth
Freshman
Freshman
 
Posts: 6
Joined: Fri May 28, 2010 11:50 am

Re: starting a text to speech engine in background

Postby streetfi8er » Fri Jun 25, 2010 8:56 pm

Thanks for the reply,
Firstly i'm not using an Activity it's a service i'm talking about
Secondly , i don't think we need to declare anything as such in the manifest flie

Here' s what my service looks like:
Code: Select all

import java.util.Locale;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.util.Log;
import android.widget.Toast;


public class Speaker extends Service implements OnInitListener{
   
   
   public static TextToSpeech mtts;
   @Override
   public IBinder onBind(Intent arg0) {
      // TODO Auto-generated method stub
      return null;
   }

   @Override
   public void onCreate(){
      Log.d("SpeakerService","Service created successfully!");
      mtts = new TextToSpeech(getApplicationContext(),this);
      
      
   }
   @Override
   public void onStart(Intent intent,int startid)
   {
      Log.d("SpeakerService","Service started successfully!");
   
      mtts = new TextToSpeech(getApplicationContext(),this);
      mtts.setLanguage(Locale.ENGLISH);
      Log.d("Creation","created mtts successfully");
      mtts.speak("Testing",TextToSpeech.QUEUE_FLUSH, null);
      Log.d("Synthesis","synthesis done successfully");
   }
   @Override
   public void onDestroy(){
      if(mtts!=null)
      {
         mtts.stop();
         Toast.makeText(getApplicationContext(),"The service has been destroyed!", Toast.LENGTH_SHORT).show();
      }
         
   }

   @Override
   public void onInit(int status) {
      // TODO Auto-generated method stub
      if(status==TextToSpeech.SUCCESS)
      {
         Log.d("tts","tts initialised successfully!");
      }
   }

}


streetfi8er
Junior Developer
Junior Developer
 
Posts: 15
Joined: Sat Jun 12, 2010 1:03 am

Re: starting a text to speech engine in background

Postby Benzebuth » Sat Jun 26, 2010 6:18 am

well, i might me wrong, but i think that first of, you have to put something like this in your manifest

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <service android:enabled="true" android:name=".Speaker">
  2.     <intent-filter>
  3.         <action android:name=".Speaker.ACTION" />
  4.     </intent-filter>
  5. </service>
  6.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


and then when you want to launch it
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent intent = new Intent(".Speaker.ACTION");  
  2. startService(intent);
  3.  
Parsed in 0.029 seconds, using GeSHi 1.0.8.4
Image
User avatar
Benzebuth
Freshman
Freshman
 
Posts: 6
Joined: Fri May 28, 2010 11:50 am

Re: starting a text to speech engine in background

Postby streetfi8er » Sat Jun 26, 2010 12:20 pm

thanks again ,but it's not working that way either :( I am getting the log message as in
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Log.d("Speech synthesis done ")
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


but am getting the toast message but no sound . I am actually starting the service through a BroadcastReceiver class as:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.    
  2.  
  3. Intent start = new Intent(".Speaker.ACTION");
  4. context.startService(start);
  5.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

is there any mistake in the way i am initialising the tts engine in the service?

the modified form is:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.example.Speaker
  2. ...
  3. public class Speaker extends Service implements OnInitListener{
  4.        
  5.        
  6.         public  TextToSpeech mtts;
  7.         Context context;
  8.         @Override
  9.         public IBinder onBind(Intent arg0) {
  10.                 // TODO Auto-generated method stub
  11.                 return null;
  12.         }
  13.  
  14.         @Override
  15.         public void onCreate(){
  16.                 Log.d("SpeakerService","Service created successfully!");
  17.                 mtts = new TextToSpeech(getApplicationContext(),this);
  18.                
  19.                
  20.         }
  21.         @Override
  22.         public void onStart(Intent intent,int startid)
  23.         {
  24.                 Log.d("SpeakerService","Service started successfully!");
  25.        
  26.                 mtts = new TextToSpeech(getApplicationContext(),this);
  27.                 mtts.setLanguage(Locale.ENGLISH);
  28.                 Log.d("Speaker3","created mtts successfully");
  29.                 Toast.makeText(getApplicationContext(), "From Service",Toast.LENGTH_SHORT );
  30.                 mtts.speak("Testing",TextToSpeech.QUEUE_FLUSH, null);
  31.                 Log.d("Speaker","synthesis done successfully");
  32.         }
  33.         @Override
  34.         public void onDestroy(){
  35.                 if(mtts!=null)
  36.                 {
  37.                         mtts.stop();
  38.                         Toast.makeText(getApplicationContext(),"The service has been destroyed!", Toast.LENGTH_SHORT).show();
  39.                 }
  40.                        
  41.         }
  42.  
  43.         @Override
  44.         public void onInit(int status) {
  45.                 // TODO Auto-generated method stub
  46.                 if(status==TextToSpeech.SUCCESS)
  47.                 {
  48.                         Log.d("Speaker","tts initialised successfully!");
  49.                 }
  50.         }
  51.  
  52. }
  53.  
Parsed in 0.041 seconds, using GeSHi 1.0.8.4
streetfi8er
Junior Developer
Junior Developer
 
Posts: 15
Joined: Sat Jun 12, 2010 1:03 am

Re: starting a text to speech engine in background

Postby Benzebuth » Mon Jun 28, 2010 4:59 pm

sorry, i hadn't any time to proceed with your querie. Maybe tomorrow i'll have a look to the tts documention.
Right now i can't help you any further
Image
User avatar
Benzebuth
Freshman
Freshman
 
Posts: 6
Joined: Fri May 28, 2010 11:50 am

Top

Re: starting a text to speech engine in background

Postby streetfi8er » Mon Jun 28, 2010 5:57 pm

ok , thanks for your concern . Looking forward for your help .
streetfi8er
Junior Developer
Junior Developer
 
Posts: 15
Joined: Sat Jun 12, 2010 1:03 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 25 guests