How can I switch between 3 languages /3 voices in a xamarin app.
I found a lot of samples for android but no one for xamarin
i tried:
public void Speak(string text)
{
Plugin.TextToSpeech.TextToSpeech ttse = new Plugin.TextToSpeech.TextToSpeech();
CrossLocale localeen;
localeen.Country = "EN";
localeen.Language = "en_EN";
ttse.Speak(text, false, localeen);
}
The text is spoken with an italian voice and not as expected in english.
Related
I'm working on localization for an app, on switching the language the tabbar should invert, i have a renderer through which i'm trying to do this
if (e.NewElement != null)
{
_tabbedController = (UITabBarController)ViewController;
ViewController.View.SemanticContentAttribute = UISemanticContentAttribute.ForceLeftToRight;
}
I'm doing this in the onElementChanged Method, but for some reason this does not seem to affect, am i doing somthing wrong in this or is there any other way to do this ?
Any help would be appreciated
There seems to be a bug in iOS 13 (Safari and WkWebView) that makes iOS use the device language voice and not find a suitable voice by looking at the 'lang' provided in the SpeechSynthesisUtterance.
I worked around the issue by setting a suitable voice myself.
This is not needed in other browsers/platforms (eg macOS Safari, iOS < 13, Chrome etc.)
this._getUtteranceRate().then((rate) => {
let utterance = new SpeechSynthesisUtterance(words);
utterance.rate = rate;
utterance.lang = 'sv-SE';
utterance.voice = this.voice; //IOS13 fix
window.speechSynthesis.speak(utterance);
});
window.speechSynthesis.onvoiceschanged = () => {
this.setVoice();
}
setVoice() {
this.voice = window.speechSynthesis.getVoices().find((voice) => {
return voice.lang === 'sv-SE';
});
}
It seems one needs to set the voice explicitly on the SpeechSynthesisUtterance for iOS13, as the locale is not used to find the voice.
I use Qt to make a multilanguage app in iOS.
and i use ".ts" and ".qm" file to translate text.
the QComboBox in ios has 2 buttons can't be translate.
the ts file need a classname, but i can't found this 2 words in any class from qt source.
I think the Cancel and Done translations are in the Qt translation. I think you need one QTranslator for your app string and a second for the Qt library strings.
The qt_*.qm files are in your Qt directory someplace.
For example, to switch to German you would need to switch two translators:
myapp_de.qm
qt_de.qm
https://wiki.qt.io/How_to_create_a_multi_language_application
See loadLanguage() is setting two QTranslators, one for app, and one for Qt.
// Called every time, when a menu entry of the language menu is called
void MainWindow::slotLanguageChanged(QAction* action)
{
if(0 != action) {
// load the language dependant on the action content
loadLanguage(action->data().toString());
setWindowIcon(action->icon());
}
}
void switchTranslator(QTranslator& translator, const QString& filename)
{
// remove the old translator
qApp->removeTranslator(&translator);
// load the new translator
if(translator.load(filename))
qApp->installTranslator(&translator);
}
void MainWindow::loadLanguage(const QString& rLanguage)
{
if(m_currLang != rLanguage) {
m_currLang = rLanguage;
QLocale locale = QLocale(m_currLang);
QLocale::setDefault(locale);
QString languageName = QLocale::languageToString(locale.language());
switchTranslator(m_translator, QString("TranslationExample_%1.qm").arg(rLanguage));
switchTranslator(m_translatorQt, QString("qt_%1.qm").arg(rLanguage));
ui.statusBar->showMessage(tr("Current Language changed to %1").arg(languageName));
}
}
I am writing a mobile app in xamarin forms and I have half the screen continuously scanning barcodes using ZXingScannerView. This works great in android however in ios it will not pick up any barcodes using ZXingScannerView. However ios does pick up barcodes using the full page ZXingScannerPage. In my example code below the method Scanner_OnScanResult is never getting hit. How can I get this to work in ios am i missing something?
ZXingScannerView scanner = new ZXingScannerView
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
AutomationId = "zxingScannerView",
IsScanning = true,
Options = new ZXing.Mobile.MobileBarcodeScanningOptions
{
UseFrontCameraIfAvailable = false,//update later to come from settings
PossibleFormats = new List<ZXing.BarcodeFormat>(),
TryHarder = true
}
};
ZXingDefaultOverlay overlay = new ZXingDefaultOverlay();
scanner.Options.PossibleFormats.Add(ZXing.BarcodeFormat.QR_CODE);.
scanner.OnScanResult += Scanner_OnScanResult;
private void Scanner_OnScanResult(ZXing.Result result)
{
DisplayAlert("Exit", "TEST", "Yes", "No");
}
I eventually got this working however i'm not sure if its a bug or just inconsistent design but in iOS IsAnalyzing must be set to true manually when working in a view
Using Xcode 7.2, different deployment targets (e. g. 7.1 and 9.2) and different virtual devices (e. g. iPhone 6s plus and iPhone 5s) I am not able to switch the spoken TTS language. Here is my code:
import UIKit
import AVFoundation
class ViewController: UIViewController {
let synth = AVSpeechSynthesizer()
var myUtterance = AVSpeechUtterance()
func speak(locale: String, text: String) {
if let voice = AVSpeechSynthesisVoice(language: locale) {
myUtterance.voice = voice
// I read that the delays might cure the issue,
// but they don't. Language switching does not
// work with or without this.
myUtterance.preUtteranceDelay = 0.005
myUtterance.postUtteranceDelay = 0.005
// I read that an empty text cures the issue,
// but is doesn't. Language switching does not
// work with or without this.
for t in [" ", text] {
myUtterance = AVSpeechUtterance(string: t)
synth.speakUtterance(myUtterance)
}
} else {
debugPrint("bad voice")
}
}
override func viewDidLoad() {
super.viewDidLoad()
speak("de-DE", text: "Ich blicke auf einen blauen Himmel!")
speak("en-US", text: "This is a text, which I like very much!")
}
}
Both texts are read, but only in the device's standard language.
Furthermore I get the following error when I run the code:
2015-12-23 12:15:20.593 HFV[6993:964424] |AXSpeechAssetDownloader|error|
ASAssetQuery error fetching results (for
com.apple.MobileAsset.MacinTalkVoiceAssets) Error Domain=ASError Code=21
"Unable to copy asset information" UserInfo={NSDescription=Unable to copy
asset information}
Running the app on an iPhone 4 (not virtual, it's a real device with iOS 7.1.2) the app starts and this error does not occur, but the TTS doesn't work at all.
Thanks a lot in advance