Skip to content

language

Xinrui Wang edited this page Dec 3, 2017 · 3 revisions

Language Processing

This class provides tools to translate sentences, translate language, break sentence, and convert text to speech via Azure service. This script is based on this project.

  1. You need to first add the following line to your gradle
dependencies {
    compile 'io.github.firemaples:microsoft-translator-java-api:0.8.5'
}
  1. Get your Azure keys.

A Windows Azure Portal Subscription Key (See the picture below, just use one of key 1 or key 2) - sign up here

  1. Put the keys in src/res/values/string.xml
<string name="microsoft_translate_key" templateMergeStrategy="preserve" translatable="false">
        **********
</string>

class TextProcess(var key:String)

Parameters:

  • key: Azure service key

Functions:

translate(message: String, from: Language, to: Language):String

This function translate message from a language to another language.

  • Parameters:
    • message(String): String to translate.
    • from(Language): input language type (could be found in public enum Language{...})
    • to(Language): output language type
    • return value(String): Translated message.

detect_language(message: String):Language

This function detects the language of the input message.

  • Parameters:
    • message(String): String to detect
    • return value(Language): language of the message

break_sentence(message: String, from: Language):Array<Int>

This function parse the sentence by providing an array of breaking positions.

  • Parameters:
    • message(String): String to parse
    • from(Language): input language type (could be found in public enum Language{...})
    • return value: an array of breaking positions

speak(message: String, language: SpokenDialect)

This function uploads the message to server and plays the audio downloaded from the provided URL.

  • Parameters:
    • message(String): String to parse
    • language(SpokenDialect): spoken dialect type (could be found in public enum SpokenDialect {...})
    • return value: NULL