Speech Recognizer not working for Other language android - locale

I am working on speech recognization which is working only for english and hindi but if i am working on other language like bengali and urdu etc for that it is not working. code written by me.
locale may be "ur" for urdu and "bn for bengali"
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, locale);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 1000);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
recognizerIntent.putExtra("android.speech.extra.DICTATION_MODE", true);

Related

Microsoft speech to text is not identifying other than english language

I am using microsoft speech to text service. my requirement is to identify and convert any spoken language on microphone should converted on text . example if i speak spanish then i should get spanish language text as response.
here is my code and am setting config by providing subscription key and endpoint url
var config = SpeechConfig.FromHost(new Uri("ws://xxxxxxxx:5000/"));
using (var recognizer = new SpeechRecognizer(config))
{
Console.WriteLine("Say something...");
var result = await recognizer.RecognizeOnceAsync();
// Checks result.
if (result.Reason == ResultReason.RecognizedSpeech)
{
Console.WriteLine($"We recognized: {result.Text}");
}
}
Please help me how to get converted any speech to text languages.
A common task for speech recognition is specifying the input (or source) language. Let's take a look at how you would change the input language to German. In your code, find your SpeechConfig, then add this line directly below it.
speech_config.speech_recognition_language="de-DE"
speech_recognition_language is a parameter that takes a string as an argument. You can provide any value in the list of supported locales/languages.
Please use the locale in the table https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support#speech-to-text
-Yutong
You can use language detection in the Speech Recognizer processing, see doc here
It has some limitations in terms of languages (see language support here).
How?
For a C# implementation, you should switch "Latency" to "Accuracy" depending on priority on the speechConfig object:
speechConfig.SetProperty(PropertyId.SpeechServiceConnection_SingleLanguageIdPriority, "Latency");
Add an AutoDetectSourceLanguageConfig config to your SpeechRecognizer:
Then you can have your result:
var autoDetectSourceLanguageConfig =
AutoDetectSourceLanguageConfig.FromLanguages(
new string[] { "en-US", "de-DE", "ja-JP", "de-DE" });
using var audioConfig = AudioConfig.FromDefaultMicrophoneInput();
using (var recognizer = new SpeechRecognizer(
speechConfig,
autoDetectSourceLanguageConfig,
audioConfig))
{
var speechRecognitionResult = await recognizer.RecognizeOnceAsync();
var autoDetectSourceLanguageResult =
AutoDetectSourceLanguageResult.FromResult(speechRecognitionResult);
var detectedLanguage = autoDetectSourceLanguageResult.Language;
}

pdfkit: generated pdf documents does not render hindi text

Does pdfkit support Hindi language? I am writing a program to generate pdf document with Hindi text
Code sample
let user = {
no: 1,
name: 'अर्जुन दाव',
age: 26,
gender: 'पुरुष'
};
console.log(user);
const doc = new PDFDocument();
doc.fontSize(36)
.fillColor('red')
.text(user.name, 50, 400);
doc.fontSize(16)
.fillColor('black')
.text(`उम्र : ${user.age}, ${user.gender}`, 50, 460);
doc.pipe(fs.createWriteStream(`./output/${user.no}.pdf`));
doc.end();
Output
It prints the user object in the console as expected. But the pdf generated with shows a bunch of weird characters in place of texts.
environment
pdfkit version: ^0.11.0
Node version: v10.19.0
Operating System: ubuntu 20.0.4
What am I doing wrong?
Download https://fonts.google.com/specimen/Tiro+Devanagari+Hindi?query=hindi
and add in your code:
doc.font('./fonts/Tiro_Devanagari_Hindi/TiroDevanagariHindi-Regular.ttf');
That worked for me with Hindi input text without converting it to English or using transliteration.

Best Way to Tranform XML to Specific XML or JSON Format in NodeJS

What's the best way to transform the XML to a specific XML Format or JSON Format ?
Which npm packages can be used ?
I'd give xml2js a try, this makes XML to JSON conversion very easy:
const xml2js = require('xml2js');
function testXmlParse(xml) {
const parser = new xml2js.Parser( { explicitArray: false })
parser.parseString(xml, (err, result) => {
if (err) {
console.error("An error occurred: ", err);
} else {
console.log("Xml to Json result: ", result);
}
})
}
const xmlInput = "<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>";
testXmlParse(xmlInput);
Here's an example of some Xml manipulation using xmldom:
const xmldom = require('xmldom');
const xpath = require('xpath');
var parser = new xmldom.DOMParser();
var serializer = new xmldom.XMLSerializer();
const xml = '<catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer\'s Guide</title><genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applicationswith XML.</description></book><book id="bk102"><author>Ralls, Kim</author><title>Midnight Rain</title><genre>Fantasy</genre><price>5.95</price><publish_date>2000-12-16</publish_date><description>A former architect battles corporate zombies,an evil sorceress, and her own childhood to become queenof the world.</description></book><book id="bk103"><author>Corets, Eva</author><title>Maeve Ascendant</title><genre>Fantasy</genre><price>5.95</price><publish_date>2000-11-17</publish_date><description>After the collapse of a nanotechnologysociety in England, the young survivors lay thefoundation for a new society.</description></book><book id="bk104"><author>Corets, Eva</author><title>Oberon\'s Legacy</title><genre>Fantasy</genre><price>5.95</price><publish_date>2001-03-10</publish_date><description>In post-apocalypse England, the mysteriousagent known only as Oberon helps to create a new lifefor the inhabitants of London. Sequel to MaeveAscendant.</description></book><book id="bk105"><author>Corets, Eva</author><title>The Sundered Grail</title><genre>Fantasy</genre><price>5.95</price><publish_date>2001-09-10</publish_date><description>The two daughters of Maeve, half-sisters,battle one another for control of England. Sequel toOberon\'s Legacy.</description></book><book id="bk106"><author>Randall, Cynthia</author><title>Lover Birds</title><genre>Romance</genre><price>4.95</price><publish_date>2000-09-02</publish_date><description>When Carla meets Paul at an ornithologyconference, tempers fly as feathers get ruffled.</description></book><book id="bk107"><author>Thurman, Paula</author><title>Splish Splash</title><genre>Romance</genre><price>4.95</price><publish_date>2000-11-02</publish_date><description>A deep sea diver finds true love twentythousand leagues beneath the sea.</description></book><book id="bk108"><author>Knorr, Stefan</author><title>Creepy Crawlies</title><genre>Horror</genre><price>4.95</price><publish_date>2000-12-06</publish_date><description>An anthology of horror stories about roaches,centipedes, scorpionsand other insects.</description></book><book id="bk109"><author>Kress, Peter</author><title>Paradox Lost</title><genre>Science Fiction</genre><price>6.95</price><publish_date>2000-11-02</publish_date><description>After an inadvertant trip through a HeisenbergUncertainty Device, James Salway discovers the problemsof being quantum.</description></book><book id="bk110"><author>O\'Brien, Tim</author><title>Microsoft .NET: The Programming Bible</title><genre>Computer</genre><price>36.95</price><publish_date>2000-12-09</publish_date><description>Microsoft\'s .NET initiative is explored indetail in this deep programmer\'s reference.</description></book><book id="bk111"><author>O\'Brien, Tim</author><title>MSXML3: A Comprehensive Guide</title><genre>Computer</genre><price>36.95</price><publish_date>2000-12-01</publish_date><description>The Microsoft MSXML3 parser is covered indetail, with attention to XML DOM interfaces, XSLT processing,SAX and more.</description></book><book id="bk112"><author>Galos, Mike</author><title>Visual Studio 7: A Comprehensive Guide</title><genre>Computer</genre><price>49.95</price><publish_date>2001-04-16</publish_date><description>Microsoft Visual Studio 7 is explored in depth,looking at how Visual Basic, Visual C++, C#, and ASP+ areintegrated into a comprehensive developmentenvironment.</description></book></catalog>';
const root = parser.parseFromString(xml);
let selectedNodes = xpath.select('//book/author', root);
var newDoc = new xmldom.DOMParser().parseFromString("<test/>");
// Move nodes to new document..
selectedNodes.forEach(function (n) {
newDoc.appendChild(n);
});
console.log("Processed Xml: ", serializer.serializeToString(newDoc));
I build camaro for that specific purpose, to extract and transform the xml input. You can see the below image to get an idea of how it works
basically, you write a xpath template specify what field you want, where is it (via xpath), how do you want to name it in json output

MS Translator API Error - not working for Serbian/Croatian

I have a question regarding MS Translator API. I followed "[Walkthrough: Microsoft Translator in a C# Console Application][1]" tutorial so I could use MS translate API from my app. When I try translating from "English" to "French" or some other language, everything works perfectly fine. But when translating from/to Serbian/Croatian, I get following error message: "Parameter: From has an invalid pattern of characters".
Since I am using automatic language detection, I didn't hard code any of the language acronyms:
string input = "Petar voli da ide u skolu"; // serbian
var sourceLanguage = Translator.DetectSourceLanguage(tc, input); // gets Croatian
var targetLanguage = PickRandomLanguage(tc); // select random language by using
// Handle the error condition
if (sourceLanguage != null)
{
var translationResult = Translator.TranslateString(tc, input, sourceLanguage, targetLanguage); // exception "Parameter: From has an invalid pattern of characters".
if (translationResult != null)
{
}
}
Is there a problem with the API, or Serbian/Croatian are not supported?
You use wrong or old script.
I use this script in php: Microsoft Translator doesn’t work in the Serbian and Croatian?
For C# use script from this page: https://msdn.microsoft.com/en-us/library/ff512421.aspx#csharpexample

Watson-js spanish SpeechToText not working

I haven't been able to set the language to spanish in the watson-js speech to text api. I think I've tried every variation of the following line:
, xarg: "Content-Language=es-us"
Has anybody achieved this? How?
exports.ATT_CREDS = {
client_id:"client_id"
, client_secret:"client_secret"
, access_token:"access_token"
, scope: "SPEECH"
, context: "Generic"
, access_token_url: "https://api.att.com/oauth/token"
, api_domain: "api.att.com"
, content_type: "audio/wav"
, xarg: "Content-Language=es-us"
};
Problem solved: documentation on watson's API was wrong. After a couple of emails it got corrected. It was something with the xarg variable. It's updated now.
AT&T Speech API

Resources