IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Text to Speech


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Mars 2011
    Messages
    140
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 140
    Par défaut Text to Speech
    Bonjour à tous.

    je veux utiliser la classe CommandeVocal pour lire un texte écrit sur un AlertDialog.

    voilà les classes

    **************HelloItemizedOverlay*************
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    import java.util.ArrayList;
     
    import android.app.AlertDialog;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.graphics.drawable.Drawable;
    import android.location.LocationListener;
    import android.net.Uri;
    import android.view.MotionEvent;
    import android.widget.TextView;
    import android.widget.Toast;
     
    import com.google.android.maps.GeoPoint;
    import com.google.android.maps.ItemizedOverlay;
    import com.google.android.maps.MapView;
    import com.google.android.maps.OverlayItem;
     
    public class HelloItemizedOverlay extends ItemizedOverlay {
     
    	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    	private Context mContext;
     
    	/*public HelloItemizedOverlay(Drawable defaultMarker) {
    		super(boundCenterBottom(defaultMarker));
    		// TODO Auto-generated constructor stub
    	}*/
     
    	public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
    		 // super(defaultMarker);
    		super(boundCenterBottom(defaultMarker));
    		   mContext = context;
    		  // HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(defaultMarker, mContext);
     
    		}
     
    	@Override
    	protected OverlayItem createItem(int i) {
    		// TODO Auto-generated method stub
    		 return mOverlays.get(i);
    	}
     
    	@Override
    	public int size() {
    		// TODO Auto-generated method stub
    		return mOverlays.size();
    	}
    	public void addOverlay(OverlayItem overlay) {
    	    mOverlays.add(overlay);
    	    populate();
    	}
     
    	@Override
    	protected boolean onTap(int index) {
    	  OverlayItem item = mOverlays.get(index);
    	  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
    	  dialog.setTitle(item.getTitle());
    	  dialog.setMessage(item.getSnippet());  
     
     
    	 dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {  		    	 
    		    	public void onCancel(DialogInterface dialog) {} 
     
    				@Override
    				public void onClick(DialogInterface dialog, int which) {			
     
    				}  
     
    		    });
     
    	 dialog.setPositiveButton("photo", new DialogInterface.OnClickListener() {
     
    		@Override
    		public void onClick(DialogInterface dialog, int which) {
    			// TODO Auto-generated method stub
     
     
     
     
     
    			Intent intent = new Intent(mContext,HelloGallery.class);
    			mContext.startActivity(intent);
     
     
     
    		}  		    	 
    		    	//public void onCancel(DialogInterface dialog) {} 
     
     
     
    		    });
     
    	 dialog.setNeutralButton("Ecouter",  new DialogInterface.OnClickListener() {
     
    		@Override
    		public void onClick(DialogInterface dialog, int which) {
    			// TODO Auto-generated method stub
     
     
    			//probleme
    			///inviter la classe CommandeVocal pour lire le texte " item.getSnippet() " au lieu de  "hello" decrite dans la classe CommadeVocal
     
    			Intent intent = new Intent(mContext,CommandeVocal.class);
    			mContext.startActivity(intent);
     
     
     
    		}  		    	 
     
     
     
    		    });
     
     
     
    	  dialog.show();
    	  return true;
    	}
     
     
     
     
    }
    *******************CommandeVocal********************

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    import java.util.Locale;
    import java.util.Random;
     
    import android.app.Activity;
    import android.os.Bundle;
    import android.speech.tts.TextToSpeech;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
     
    public class CommandeVocal extends Activity implements TextToSpeech.OnInitListener {
    	private static final String TAG = "TextToSpeechDemo";
     
        private TextToSpeech mTts;
        private Button mAgainButton;
     
    	/** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.text_to_speech);
     
          //instanciation de l'objet *mTts
            mTts = new TextToSpeech(this,
                this  // TextToSpeech.OnInitListener
                );
     
     
            mAgainButton = (Button) findViewById(R.id.again_button);
     
            mAgainButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                	ParleandroidPhone();
                }
            });
     
        }
     
        @Override
        public void onDestroy() {
            // Don't forget to shutdown!
            if (mTts != null) {
                mTts.stop();
                mTts.shutdown();
            }
     
            super.onDestroy();
        }
     
     // Implements TextToSpeech.OnInitListener.
        public void onInit(int status) {
            // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR.
            if (status == TextToSpeech.SUCCESS) {
            	//le choix de la langue ici français
               int result = mTts.setLanguage(Locale.FRANCE);
             // vérification ici si cette langue est supporté par le terminal et si elle existe
                if (result == TextToSpeech.LANG_MISSING_DATA ||
                    result == TextToSpeech.LANG_NOT_SUPPORTED) {
     
                	//renvoi une erreur sur la console logcat.
                    Log.e(TAG, "Language is not available.");
                } else {
     
                    mAgainButton.setEnabled(true);
                    // Greet the user.
                    ParleandroidPhone();
                }
            } else {
                // Initialization failed.
                Log.e(TAG, "Could not initialize TextToSpeech.");
            }
        }
     
        private static final Random RANDOM = new Random();
        private static final String[] HELLOS = {
          "Bonjour",
          "Comment tu vas",
          "abidjan",
          "Je t'aime Guy"      
        };
     
        private void ParleandroidPhone() {
        	// choix aléatoire de la phrase.
     
        	int helloLength = HELLOS.length;
     
        	String hello = HELLOS[RANDOM.nextInt(helloLength)];
     
        	mTts.speak(hello,TextToSpeech.QUEUE_FLUSH,null);
        }
    }
    sachant que j'ai déclaré les activités dans le Manifest.xml

    merci

  2. #2
    Rédacteur
    Avatar de MrDuChnok
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2002
    Messages
    2 112
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juin 2002
    Messages : 2 112
    Par défaut
    Et ?
    Tu as un bug ? Une exception ? tout se passe bien ?

  3. #3
    Membre confirmé
    Inscrit en
    Mars 2011
    Messages
    140
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 140
    Par défaut
    mon probleme est de determiner à la classe CommandeVocal de lire un texte specifique de la l'alertDialog, non pas les chaines definie dans CommandeVocal

  4. #4
    Rédacteur
    Avatar de MrDuChnok
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2002
    Messages
    2 112
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juin 2002
    Messages : 2 112

  5. #5
    Membre confirmé
    Inscrit en
    Mars 2011
    Messages
    140
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 140
    Par défaut
    un grand merci.

    ça marche maintenant

  6. #6
    Rédacteur
    Avatar de MrDuChnok
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2002
    Messages
    2 112
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juin 2002
    Messages : 2 112
    Par défaut
    Si votre problème est résolu, merci de cliquer sur le bouton adéquat.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Text To Speech ?
    Par [ZiP] dans le forum Composants VCL
    Réponses: 2
    Dernier message: 30/07/2009, 07h04
  2. [WD-2007] Text to Speech
    Par medchok dans le forum Word
    Réponses: 0
    Dernier message: 10/07/2009, 22h45
  3. Réponses: 1
    Dernier message: 02/04/2009, 18h55
  4. Mixer des fichiers SON / Text To Speech
    Par mLk92 dans le forum Langage
    Réponses: 2
    Dernier message: 03/12/2007, 10h07
  5. TTS (Text to speech) et LCC-WIN32
    Par Hummul dans le forum Windows
    Réponses: 3
    Dernier message: 31/08/2007, 16h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo