Search code examples
androidandroid-intentlocalebarcodetext-to-speech

Android Local changing when using TTS to speak a String from BARCODE scanner via intent


I'm am developing an application that scans barcodes using an external application via intent (Barcode scanner). After receiving the result of the scan, i use this result to find a texte in a database this texte can be either english or french, then i send it via another intent to another activity wich will do the sound synthesis via TTS . My application is supposed to support french and english languages. I managed to do this by playing with booleens this way :

private String localelang = Locale.getDefault().getISO3Language();
private boolean is_fr = localelang.equalsIgnoreCase("fra");

My goal is to force my app to force TTS to talk english accent if the locals are not french (so they can be japannese or whatever my TTS should keep the english accent).

I intetionnaly choose for the device a language other than frnech or english and here comes the problem. Because after invoking Barcode scanner my locals seems to change to match the device once because of this external intent to Barcode scanner, and whatever i try my TTS talk the accent of the device.

I know that it seems complicated but my code is too long to sent in a message. This is one solution between a lot that i've been trying but in vain :

 public void onInit(int status) {       
        String synthesis = Aparler.toString();
    if (!is_fr){
        vocal.setLanguage(Locale.US);               
        vocal.speak( synthesis, TextToSpeech.QUEUE_FLUSH,null);
    }
    else if(is_fr){
        vocal.setLanguage(Locale.FRANCE);           
        vocal.speak( synthesis, TextToSpeech.QUEUE_FLUSH,null);
    }

When i ommit the barcode scanner everything goes fine, i'm sure that the fact of invoking another app via intnent is the responsible for this. I can't even debug it because the AVD does not support the camera to scan ... It's really frustrating... Thanks for helping me and excuse my poor english.


Solution

  • I found that there is an option is text to spech settings wich override my language's choices , i disabled it, and all works like a charm !