Flutter: Text to Voice Tamil language is support? - flutter

I have trying to convey my text to speech tamil language but it not support any other way is there?
Am using : flutter_tts package
my code:
speak() async {
final languages = await Tts.getAvailableLanguages();
var isGoodLanguage = await Tts.isLanguageAvailable("ta");
print(isGoodLanguage);
await Tts.setLanguage("tamil");
Tts.speak('வாழ்ந்த காலம்: 2 ஆம் நூறாண்டு முதல் 8 நூற்றாண்டு வரை'); }
But it's not working anyone tried with tamil text to voice please help me. Thanks.

If "ta" is a supported language code on your device (You should receive the list of supported language codes when you run await Tts.getAvailableLanguages()), you should use that to set the language rather than "tamil".
Change: await Tts.setLanguage("tamil");
To: await Tts.setLanguage("ta");

Related

text to speech arabic in flutter

I am searching for Text to speech package in flutter and I found this one flutter_tts
but its not supporting Arabic language is there any way to Add Arabic language or any other package that Supports Arabic language ?
Use Flutter speech_to_text package.
to change language, localeId = the ID of the Arabic language on this device:
var locales = await speech.locales();
// Some UI or other code to select a locale from the list
// resulting in an index, selectedLocale
var selectedLocale = locales[selectedLocale];
speech.listen(
onResult: resultListener,
localeId: selectedLocale.localeId,
);

how to get country code like(+91 ,+1 etc) using user's current location flutter

I'm working on flutter app and I have a text widget where I want to show user's current country code based on his location without any dropdown.
I'm getting value like "IN","US" using Locale, but I don't want it,
I need numeric country code like +91 (for India), +1 (for US) etc.
anyone help me please.
You can use these files countries.dart and country.dart
Get the user country code from http://ip-api.com/json with http package and then use it to get the country phone code from countryList:
Future<String> getCountryPhoneCode() async {
var response = await http.get(Uri.parse('http://ip-api.com/json'));
var jsonResponse = json.decode(response.body);
final isoCode = jsonResponse['countryCode'];
print("country code " + isoCode);
return "+" +
countryList
.firstWhere((element) => element.isoCode == isoCode,
orElse: () => countryList.first)
.phoneCode;
}
I tested this and it works for me but you can improve it to avoid http exceptions
You can use country_codes package:
Install:
dependencies:
country_codes: ^2.0.1
Usage:
await CountryCodes.init(); // Optionally, you may provide a `Locale` to get countrie's localizadName
final CountryDetails details = CountryCodes.detailsForLocale();
print(details.alpha2Code); // Displays alpha2Code, for example US.
print(details.dialCode); // Displays the dial code, for example +1.
print(details.name); // Displays the extended name, for example United States.
print(details.localizedName);

Flutter Speech to Text in Arabic Language

Is there is a way to convert speech into text using flutter (specially if the the speech in Arabic and also I want the resulted text in Arabic) I've found many resources that explains how speech to text in English but not Arabic so I hope anyone can help me.
Use Flutter speech_to_text library.
to change language, localeId = the ID of the Arabic language on this device:
var locales = await speech.locales();
// Some UI or other code to select a locale from the list
// resulting in an index, selectedLocale
var selectedLocale = locales[selectedLocale];
speech.listen(
onResult: resultListener,
localeId: selectedLocale.localeId,
);

How to handle auto direction of text with dart-flutter?

I need to make auto-detection for posts language to change the text direction according to language, I Used 'firebase_mlkit_language.dart' to make the auto-detection of language.
this is a screenshot of screen:
I need the English post alignment to be from ltr.
this Function I made to check lang
Future<String> checkLang(String text)async{
final LanguageIdentifier languageIdentifier = FirebaseLanguage.instance.languageIdentifier();
final List<LanguageLabel> labels = await languageIdentifier.processText(text);
for (LanguageLabel label in labels) {
final String text = label.languageCode;
final double confidence = label.confidence;
}
return labels[0].languageCode;
}
while getposts function is processing and get the posts from firebase, I added this line to get a list of posts language
postsLang.add(checkLang(PostModel.fromJson(element.data()).text).toString());
then while generating the posts UI, in the post widget i made this condition to check whether the language is Arabic 'ar'
so, the direction should be from right to left.
textDirection: AppCubit.get(context).postsLang[index].toString() == 'ar' ?TextDirection.rtl:TextDirection.ltr,

Flutter open whatsapp with text message

I want to open whatsapp from my Flutter application and send a specific text string. I'll select who I send it to when I'm in whatsapp.
After making some research I came up with this:
_launchWhatsapp() async {
const url = "https://wa.me/?text=Hey buddy, try this super cool new app!";
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Which works ok ish, however there are two problems:
As soon as I make the text string into multi words it fails. So if I change it to:
_launchWhatsapp() async {
const url = "https://wa.me/?text=Hey buddy, try this super cool new app!";
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Then the Could not launch $url is thrown.
I have whatsapp already installed on my phone, but it doesn't go directly to the app, instead it gives me a webpage first and the option to open the app.
Here is the webpage that I see:
Any help on resolving either of these issues would be greatly appreciated.
Thanks
Carson
P.s. I'm using the Url_launcher package to do this.
From the official Whatsapp FAQ, you can see that using "Universal links are the preferred method of linking to a WhatsApp account".
So in your code, the url string should be:
const url = "https://wa.me/?text=YourTextHere";
If the user has Whatsapp installed in his phone, this link will open it directly. That should solve the problem of opening a webpage first.
For the problem of not being able to send multi-word messages, that's because you need to encode your message as a URL. Thats stated in the documentation aswell:
URL-encodedtext is the URL-encoded pre-filled message.
So, in order to url-encode your message in Dart, you can do it as follows:
const url = "https://wa.me/?text=Your Message here";
var encoded = Uri.encodeFull(url);
As seen in the Dart Language tour.
Please note that in your example-code you have put an extra set of single quotes around the text-message, which you shouldn't.
Edit:
Another option also presented in the Whatsapp FAQ is to directly use the Whatsapp Scheme. If you want to try that, you can use the following url:
const url = "whatsapp://send?text=Hello World!"
Please also note that if you are testing in iOS9 or greater, the Apple Documentation states:
Important
If your app is linked on or after iOS 9.0, you must declare the URL schemes you pass to this method by adding the LSApplicationQueriesSchemes key to your app's Info.plist file. This method always returns false for undeclared schemes, whether or not an appropriate app is installed. To learn more about the key, see LSApplicationQueriesSchemes.
So you need to add the following keys to your info.plist, in case you are using the custom whatsapp scheme:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
till date: 27-06-2022
using package: https://pub.dev/packages/url_launcher
dependencies - url_launcher: ^6.1.2
TextButton(
onPressed: () {
_launchWhatsapp();
},
)
_launchWhatsapp() async {
var whatsapp = "+91XXXXXXXXXX";
var whatsappAndroid =Uri.parse("whatsapp://send?phone=$whatsapp&text=hello");
if (await canLaunchUrl(whatsappAndroid)) {
await launchUrl(whatsappAndroid);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("WhatsApp is not installed on the device"),
),
);
}
}
Here is new update way...
whatsapp() async{
var contact = "+880123232333";
var androidUrl = "whatsapp://send?phone=$contact&text=Hi, I need some help";
var iosUrl = "https://wa.me/$contact?text=${Uri.parse('Hi, I need some help')}";
try{
if(Platform.isIOS){
await launchUrl(Uri.parse(iosUrl));
}
else{
await launchUrl(Uri.parse(androidUrl));
}
} on Exception{
EasyLoading.showError('WhatsApp is not installed.');
}
}
and call whatsapp function in onpress or ontap function
For using the wa.me domain, make sure to use this format...
https://wa.me/123?text=Your Message here
This will send to the phone number 123. Otherwise, you will get an error message (see? https://wa.me/?text=YourMessageHere ). Or, if you don't want to include the phone number, try this...
https://api.whatsapp.com/send?text=Hello there!
Remember, wa.me requires a phone number, whereas api.whatsapp.com does not. Hope this helps!
I know it is too late for answering this, but for those who want the same functionality, the current way is to do it like this:
launchUrl(Uri.parse('https://wa.me/$countryCode$contactNo?text=Hi'),
mode: LaunchMode.externalApplication);
if you will use URL Launcher then the whatsapp link will be open on web browser. So you need to set parameter - not to open on safari browser. The complete code you can find on this flutter tutorial.
But for your case use below code.
await launch(whatappURL, forceSafariVC: false);
Today i am adding solution its working fine on my desktop and phone
Add 91 if your country code is +91
Remember not add any http or https prefix otherwise wont work.
whatsapp://send?phone=9112345678&text=Hello%20World!