When I change the language attribute, it still plays in English, here is my code, (Making a TTS OCR)
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.V7.App;
using Android.Views;
using Android.Gms.Vision;
using Android.Util;
using Android.Gms.Vision.Texts;
using Android.Graphics;
using Android.Runtime;
using System;
using Android.Support.V4.App;
using Android;
using Android.Content.PM;
using static Android.Gms.Vision.Detector;
using Java.Lang;
using Android.Speech.Tts;
using Java.Util;
using Android.Content;
namespace rectext
{
[Activity(Label = "PicSpeak", MainLauncher = true, Icon = "@drawable/start", Theme = "@style/Theme.AppCompat.Light.NoActionBar")]
public class MainActivity : AppCompatActivity, ISurfaceHolderCallback, IProcessor, TextToSpeech.IOnInitListener
{
private Button SetUp;
private SurfaceView cameraView;
private TextView textView;
private CameraSource cameraSource;
private const int RequestCameraPermisionID = 1001;
private TextView text_view;
private Button btnSpeak;
private TextToSpeech tts;
private FrameLayout pCameraLayout = null; // this layout contains surfaceview
private ZoomControls zoomControls;
Camera mCamera = null;
StringBuilder message = new StringBuilder();
public void OnInit([GeneratedEnum] OperationResult status)
{
if (status == OperationResult.Success)
{
tts.SetLanguage(Locale.Taiwan);
tts.SetPitch(-0.5f);
tts.SetSpeechRate(2.0f);
SpeakOut();
}
}
private void SpeakOut()
{
string text = text_view.Text;
if (!string.IsNullOrEmpty(text))
tts.Speak(text, QueueMode.Flush, null);
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
switch (requestCode)
{
case RequestCameraPermisionID:
{
if (grantResults[0] == Permission.Granted)
{
message.Append("Permission granted");
cameraSource.Start(cameraView.Holder);
}
else
{
message.Append("Permission not granted");
}
}
break;
default:
message.Append($"{requestCode} is not handled");
break;
}
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button btnShow = FindViewById<Button>(Resource.Id.btnShowAbout);
btnShow.Click += delegate
{
StartActivity(new Android.Content.Intent(this, typeof(About)));
};
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
SupportActionBar.Title = "Text To Speech";
tts = new TextToSpeech(this, this);
text_view = FindViewById<TextView>(Resource.Id.text_view);
btnSpeak = FindViewById<Button>(Resource.Id.btnSpeak);
btnSpeak.Click += delegate
{
SpeakOut();
};
cameraView = FindViewById<SurfaceView>(Resource.Id.surface_view);
textView = FindViewById<TextView>(Resource.Id.text_view);
Button language = FindViewById<Button>(Resource.Id.language);
language.Click += delegate
{
StartActivity(typeof(Activity1));
};
CheckBox Hide = FindViewById<CheckBox>(Resource.Id.Hide);
Toolbar toolbar3 = FindViewById<Toolbar>(Resource.Id.toolbar3);
Hide.Click += delegate
{
if (Hide.Checked == true)
{
toolbar3.Visibility = Android.Views.ViewStates.Gone;
}
else
{
toolbar3.Visibility = Android.Views.ViewStates.Visible;
}
};
TextRecognizer textRecognizer = new TextRecognizer.Builder(ApplicationContext).Build();
if (textRecognizer.IsOperational)
{
cameraSource = new CameraSource.Builder(ApplicationContext, textRecognizer)
.SetFacing(CameraFacing.Back)
.SetRequestedPreviewSize(1280, 1024)
.SetRequestedFps(2.0f)
.SetAutoFocusEnabled(true)
.Build();
cameraView.Holder.AddCallback(this);
textRecognizer.SetProcessor(this);
}
else
{
Log.Error("Main Activity", "Detector dependencies are not yet available");
}
}
private void @delegate(object sender, EventArgs e)
{
throw new NotImplementedException();
}
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height)
{
}
public void SurfaceCreated(ISurfaceHolder holder)
{
if (ActivityCompat.CheckSelfPermission(ApplicationContext, Manifest.Permission.Camera) != Android.Content.PM.Permission.Granted)
{
//Request permission
ActivityCompat.RequestPermissions(this, new string[]
{
Android.Manifest.Permission.Camera
}, RequestCameraPermisionID);
return;
}
cameraSource.Start(cameraView.Holder);
}
public void SurfaceDestroyed(ISurfaceHolder holder)
{
cameraSource.Stop();
}
public void ReceiveDetections(Detections detections)
{
SparseArray items = detections.DetectedItems;
if (items.Size() != 0)
{
textView.Post(() =>
{
StringBuilder strBuilder = new StringBuilder();
for (int i = 0; i < items.Size(); ++i)
{
strBuilder.Append(((TextBlock)items.ValueAt(i)).Value);
strBuilder.Append("\n");
}
textView.Text = strBuilder.ToString();
});
}
}
public void Release()
{
}
}
}