How to get pronounce of the word in Google translate api? - google-translate

In google translate website, if we translate it shows translation and also pronounce of the word.
But when I use the Google translate rest API, it only return the translation, I need pronounce of the word same as website.
My Rest API
https://translation.googleapis.com/language/translate/v2?key=myApiKey&q=%D8%A7%D9%84%D8%A8%D8%B3%D8%AA%D8%A7%D9%86&source=ar&target=en
I may miss something, is any extra parameters there to retrieve these extra information?

Translating a word from the alphabet of one language to another(get the pronuntiation), is named transliteration and it is not supported by Cloud Translate API yet.
However, there is a feature request filed for the same. You can vote for this feature by clicking "+1" and "STAR" mark to recieve updates on it.

I was also looking for the same answer.
I haven't found a way to get Pronuntiation with the Google Translate API yet.
However, I found a way to get it through the Python library.
You can use the Python googletrans library.
The code is as follows.
You must use googletrans library 3.1.0a0 to avoid errors.
# pip install googletrans==3.1.0a0
from googletrans import Translator
translator = Translator()
SENTENSE = "안녕하세요. 반갑습니다."
LANGUAGE_CODE = translator.detect(SENTENSE).lang
k = translator.translate(SENTENSE, dest=LANGUAGE_CODE)
print(k)
print(k.text)
print(k.pronunciation)
Output:
Translated(src=ko, dest=ko, text=안녕하세요. 반갑습니다., pronunciation=annyeonghaseyo. bangabseubnida., extra_data="{'translat...")
안녕하세요. 반갑습니다.
annyeonghaseyo. bangabseubnida.

Related

Here API | MultiValueQueryParameter for Via Points

I'm using the latest version of the here javascript sdk 3.1.32.0
When I use H.service.Url.MultiValueQueryParameter for my via points like
{
...,
via: new H.service.Url.MultiValueQueryParameter(['50.1234,8.7654', '51.2234,9.1123']);
}
I see in the URL params of my request this: &via=%5Bobject%20Object%5D
Someone an idea why this happens?
Thanks in advance!
When you use "via" parameter, you define a list of via waypoints. A via waypoint is not a native datatype recongnized by JavaScript, therefore, you will see in the URL params the word object refering to a particular data structure, in this case the via Waypoint composed mainly by Latitude, Longitude.
Regards.
This took a while to figure out the actual issue with the malformed url params. I was dynamically loading the here maps service script on mount of a component. Accidentally this happened in some cases twice. In both cases H was globally available and everything worked like expected. BUT when the script was loaded twice H.service.Url.MultiValueQueryParameter didn't return the correct params. It basically encoded them twice, or tried to.
The other side issue was that https://www.npmjs.com/package/#types/heremaps is outdated and doesn't cover MultiValueQueryParameter. So I had to remove the types and use my own. Else I probably would have realized the issue earlier.

Google.Cloud.Translate.V3 only gives one translation result

I just switched from Google.Cloud.Translate.V2 to Google.Cloud.Translate.V3, expecting to get multiple translation options, but I only get one.
The example code seems geared for it:
foreach (Translation translation in response.Translations)
{
Console.WriteLine($"Translated text: {translation.TranslatedText}");
}
For example, the Google Translate web page translates the Spanish "Cumplan" with a main translation of English "meet" and other possibilities listed in a pane below, i.e.:
Translations of cumplir
comply
cumplir, consentir, compadecer
fulfill
cumplir, realizar
accomplish
lograr, cumplir, realizar, conseguir, alcanzar, llevar a cabo
satisfy
satisfacer, cumplir, cumplir con, aplacar, contentar, liquidar
etc.
How can I get those additional translations?
Is there a way to get the frequency it lists?
The cloud translation API doesn't support all the alternative translations - much to my chagrin - so you can't get them (as of October 2020).
The support for 'multiple' translations refers to the fact that the API supports your passing a list of strings to be translated, and so can return a response containing the translations for each string you sent it.
The API supports the translation of fairly large blocks of text, so if it returned a simple list of all the possible translations it would be really long. If there were just three words in the whole text with five possible translations instead of one, you'd have 125 different possibilities. What's needed is a more complex data structure to capture all the reasonable alternatives.
N.B. there are some existing feature requests around this issue, which you can view and indicate your interest in by 'starring' them here.

Pass search strategy to filter from rest URI

First time using api-platform and Symfony 4 to create an API interface for a MySQL db.
I'm updating an old search interface for the db for which I need to replicate many of the search options. This includes being able to search on a given field using various matching operators/strategies. e.g. starts with, contains exactly equals, etc.
I've set everything up for the api using Annotations.
The #ApiFilter(SearchFilter::class, properties={"fieldname": "strategy"} annotation on my table class works as designed, but I am limited to one-and-only-one strategy per field. I need to be able to pass the strategy to the api search function in the url. something like:
/api/staff?lastname[start]=dav
or
/api/staff?lastname=david&match=contains
or
/api/staff/lastname/son?searchtype=end
would be fine.
I can't figure out how to set this up. Shockingly, to me anyway, this common requirement doesn't seem to be documented at all.
The file CustomSearchFilter.php located at the repo https://github.com/jordonedavidson/custom_search_filter solves this use-case using the
/api/staff?lastname[start]=dav
syntax.
The file was written by Kévin Dunglas (the author of Api Platform) and is presented with his blessing.

URL format for Google News RSS feed

Google deprecated the old RSS feed URL format December 1st 2017 (deprecation notice), in addition to that they dropped the button in the Google News interface to generate a RSS URL (news mentioning this change).
This means that there is no public or documented method of generating a new RSS link. The only documentation they have is out of date since they changed the interface.
What is the new format for generating a RSS feed for a Google News topic?
Found an up-to-date library (1) that uses Google News RSS.
The URL new format seems to be:
Top news:
https://news.google.com/news/rss
By major topic:
https://news.google.com/news/rss/headlines/section/topic/{topic}
Where {topic} is one of the following values: WORLD NATION BUSINESS TECHNOLOGY ENTERTAINMENT SPORTS SCIENCE HEALTH
By any/custom topic:
Once at https://news.google.com, browse to the desired topic, for example this. Identify the topic ID in its URL, e.g. CAAqIQgKIhtDQkFTRGdvSUwyMHZNR056T1hFU0FtVnVLQUFQAQ, and use the format:
https://news.google.com/rss/topics/{id}?hl={lang}
In the format above, essentially rss/ is added after https://news.google.com/.
By geolocation:
https://news.google.com/news/rss/headlines/section/geo/{location}
Not sure about the formatting for the {location} parameter
By search query:
New link: https://news.google.com/rss/search?q={query}
Old link: https://news.google.com/news/rss/search/section/q/{query}
Where the {query} parameter is a free text search
Specifying country and language:
For example if you wish to have news in Swedish and located from Swedish sources, add the following query string to the URL to change country and language to sv-SE:
?hl=sv&gl=SE&ceid=SE%3Asv
Requests to the Geo endpoint seem to be working again.
e.g. https://news.google.com/news/rss/headlines/section/geo/{place_name}
Also, if you use the non-geo search, you can specify a 7-day window by adding +when:7d to your search.
e.g. https://news.google.com/rss/search?q={key_words}+when:7d
This options isn't valid anymore:
https://news.google.com/news/rss/headlines/section/topic/{topic}
produces Error 500.
This seems to work:
https://news.google.com/news?cf=all&hl=en&pz=1&ned=us&q=astronomy&output=rss
The Geolocation mentioned above still works too. You can also specify city and state:
https://news.google.com/news/rss/headlines/section/geo/DenverCo
Updated Google RSS News Feed
You can try this as well.
https://news.google.com/rss?hl=en-NG&gl=NG&ceid=NG:en
I was also looking for documentation. This is the best article I found.
https://blog.newscatcherapi.com/google-news-rss/
If using search you can also specify not to include articles with a certain keyword.
e.g. if I wanted to search for pages that contain the word "apple" with out the word "pie" you can specify
q=apple%20-pie
or in full
https://news.google.com/rss/search?q=apple%20-pie&hl=en-GB&gl=UK&ceid=GB:en
The RSS feed for top stories is the simplest one. Just append RSS to the https://news.google.com and you get the RSS feed of the top stories of your location.
https://news.google.com/rss
Know more

Marklogic Rest API for directory-query

I have the following XQuery which I use to fetch documents for a directory.
xquery version "1.0-ml";
cts:search(fn:collection(), cts:directory-query("/Path/To/Docs/", "infinity"))
Now I need to translate this into a REST call but I can't seem to crack it following the documentation on this page.
https://docs.marklogic.com/REST/GET/v1/search
Update:
using the Jersey REST API, It tried this but got 406 Error
String query = "{\"queries\":[ {\"directory-query\":{\"uri\":[\"/Path/to/Docs/\"]},\"infinite\":true} ]}";
String encodedQuery = URLEncoder.encode(query, "UTF-8");
WebTarget target = searchWebTarget.queryParam("structuredQuery", encodedQuery);
final Response response = target.request().get();
Any ideas?
As David said, you don't need to use structured query for this purpose, but in case you have future need:
I believe your original issue was that this is not a well-formed structured query:
{\"queries\":[ {\"directory-query\":{\"uri\":[\"/Path/to/Docs/\"]},\"infinite\":true} ]}
You're missing the top level "query" property. You can find an example of a fully formed structured query that uses directory-query here:
http://docs.marklogic.com/guide/search-dev/structured-query#id_97452
Also, you're probably already aware, but there is a native Java API that sits atop the REST API. You can learn more about this API here:
https://docs.marklogic.com/javadoc/client/index.html
http://docs.marklogic.com/guide/java
Constraining by directory is a query parameter directly on the search API. NO other notation needed.
See the docs here: https://docs.marklogic.com/REST/GET/v1/search

Resources