Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

R client for the Google Translation API, Google Cloud Natural Language API and Google Cloud Speech API

License

NotificationsYou must be signed in to change notification settings

ropensci/googleLanguageR

Repository files navigation

CRANBuild Statuscodecov.io

Language tools for R via Google Machine Learning APIs

Read theintroduction blogpost on rOpenSci's blog

This package contains functions for analysing language through theGoogle Cloud Machine LearningAPIs

Note all are paid services, you will need to provide your credit carddetails for your own Google Project to use them.

The package can be used by any user who is looking to take advantage ofGoogle’s massive dataset to train these machine learning models. Someapplications include:

  • Translation of speech into another language text, via speech-to-textthen translation and having the results spoen back to you
  • Talking Shiny apps
  • Identification of sentiment within text, such as from Twitter feeds
  • Pulling out the objects of a sentence, to help classify texts andget metadata links from Wikipedia about them.

The applications of the API results could be relevant to business orresearchers looking to scale text analysis.

Google Natural Language API

Google Natural Language API reveals the structure and meaning of textby offering powerful machine learning models in an easy to use RESTAPI. You can use it to extract information about people, places,events and much more, mentioned in text documents, news articles orblog posts. You can also use it to understand sentiment about yourproduct on social media or parse intent from customer conversationshappening in a call center or a messaging app.

Read moreon the Google Natural LanguageAPI

Google Cloud Translation API

Google Cloud Translation API provides a simple programmatic interfacefor translating an arbitrary string into any supported language.Translation API is highly responsive, so websites and applications canintegrate with Translation API for fast, dynamic translation of sourcetext from the source language to a target language (e.g. French toEnglish).

Read moreon the Google Cloud TranslationWebsite

Google Cloud Speech-to-Text API

Google Cloud Speech-to-Text API enables you to convert audio to textby applying neural network models in an easy to use API. The APIrecognizes over 80 languages and variants, to support your global userbase. You can transcribe the text of users dictating to anapplication’s microphone or enable command-and-control through voiceamong many other use cases.

Read moreon the Google Cloud SpeechWebsite

Google Cloud Text-to-Speech API

Google Cloud Text-to-Speech enables developers to synthesizenatural-sounding speech with 30 voices, available in multiplelanguages and variants. It applies DeepMind’s groundbreaking researchin WaveNet and Google’s powerful neural networks to deliver thehighest fidelity possible. With this easy-to-use API, you can createlifelike interactions with your users, across many applications anddevices.

Read moreon the Google Cloud Text-to-SpeechWebsite

Installation

  1. Create aGoogle API ConsoleProject
  2. Within your project, add apayment method to theproject
  3. Within your project, check the relevant APIs are activated
  1. Generate a service accountcredentialas a JSON file by firstcreating a service account and thencreating credentials for a service account
  2. Return to R, and install the official release viainstall.packages("googleLanguageR"), or the development versionwithremotes::install_github("ropensci/googleLanguageR")

Docker image

Some Docker images are publicly available. In generalgcr.io/gcer-public/googleLanguageR:$BRANCH_NAME carries that GitHub branch's version.

  • gcr.io/gcer-public/googleLanguageR:CRAN - the latest CRAN versionCRAN
  • gcr.io/gcer-public/googleLanguageR:master - latest GitHub master versionBuild Status
  • gcr.io/gcer-public/googleLanguageR:feature - a feature branch from GitHub

Usage

Authentication

The best way to authenticate is to use an environment file. See?Startup. I usually place this in my home directory. (e.g. if usingRStudio, click onHome in the file explorer, create a newTEXT fileand call it.Renviron)

Set the file location of your download Google Project JSON file in aGL_AUTH argument:

#.RenvironGL_AUTH=location_of_json_file.json

Then, when you load the library you should auto-authenticate:

library(googleLanguageR)

You can also authenticate directly using thegl_auth function pointingat your JSON auth file:

library(googleLanguageR)gl_auth("location_of_json_file.json")

You can then call the APIs via the functions:

  • gl_nlp() - Natural Langage API
  • gl_speech() - Cloud Speech-to-Text API
  • gl_translate() - Cloud Translation API
  • gl_talk() - Cloud Text-to-Speech API

Natural Language API

The Natural Language API returns natural language understandingtechnolgies. You can call them individually, or the default is to returnthem all. The available returns are:

  • Entity analysis - Finds named entities (currently proper names andcommon nouns) in the text along with entity types, salience,mentions for each entity, and other properties. If possible, willalso return metadata about that entity such as a Wikipedia URL. Ifusing thev1beta2 endpoint this also includes sentiment for eachentity.
  • Syntax - Analyzes the syntax of the text and provides sentenceboundaries and tokenization along with part of speech tags,dependency trees, and other properties.
  • Sentiment - The overall sentiment of the text, represented by amagnitude[0, +inf] and score between-1.0 (negative sentiment)and1.0 (positive sentiment).

Demo for Entity Analysis

You can pass a vector of text which will call the API for each element.The return is a list of responses, each response being a list of tibblesholding the different types ofanalysis.

texts<- c("to administer medicince to animals is frequently a very difficult matter, and yet sometimes it's necessary to do so","I don't know how to make a text demo that is sensible")nlp_result<- gl_nlp(texts)# two results of lists of tibblesstr(nlp_result,max.level=2)

See more examples and detailson thewebsiteor viavignette("nlp", package = "googleLanguageR")

Google Translation API

You can detect the language viagl_translate_detect, or translate anddetect language viagl_translate

Note this is a lot more refined than the free version on Google’stranslationwebsite.

text<-"to administer medicine to animals is frequently a very difficult matter, and yet sometimes it's necessary to do so"## translate British into Danishgl_translate(text,target="da")$translatedText

See more examples and detailson thewebsiteor viavignette("translate", package = "googleLanguageR")

Google Cloud Speech-to-Text API

The Cloud Speech-to-Text API provides audio transcription. Itsaccessible via thegl_speech function.

A test audio file is installed with the package which reads:

“To administer medicine to animals is frequently a very difficultmatter, and yet sometimes it’s necessary to do so”

The file is sourced from the University of Southampton’s speechdetection (http://www-mobile.ecs.soton.ac.uk/newcomms/) group and isfairly difficult for computers to parse, as we see below:

## get the sample source filetest_audio<- system.file("woman1_wb.wav",package="googleLanguageR")## its not perfect but...:)gl_speech(test_audio)$transcript## # A tibble: 1 x 2##   transcript                                                    confidence##   <chr>                                                         <chr>## 1 to administer medicine to animals is frequency of very diffi… 0.9180294

See more examples and detailson thewebsiteor viavignette("speech", package = "googleLanguageR")

Google Cloud Text-to-Speech API

The Cloud Text-to-Speech API turns text into talk audio files. Itsaccessible via thegl_talk function.

To use, supply your text to the function:

gl_talk("This is a talking computer.  Hello Dave.")

See more examples and detailson thewebsiteor viavignette("text-to-speech", package = "googleLanguageR")

ropensci_footer


[8]ページ先頭

©2009-2025 Movatter.jp