Coder Social home page Coder Social logo

joshskeen / bing_translator-gem Goto Github PK

View Code? Open in Web Editor NEW

This project forked from relrod/bing_translator-gem

0.0 1.0 0.0 79 KB

A simple Ruby interface to Bing's translation API.

Home Page: https://rubygems.org/gems/bing_translator

License: MIT License

bing_translator-gem's Introduction

Bing Translator

This gem wraps the Microsoft Bing HTTP Translate API. I am in no way affiliated with Microsoft or Bing. Use this gem at your own risk.

Released under MIT. Tested with MRI 2.0.0, 1.9.3 and 1.8.7.

Installation

To use this rubygem:

$ sudo gem install bing_translator

With bundler:

gem "bing_translator", "~> 3.2.0"

Information

Version 2.0.0+ of bing_translator uses the new OAuth-based Bing authentication.

Documentation on the Microsoft Translator API is here

bing_translator is also smart about requesting the token, and handles this behind the scenes. It will only request a token if it knows the old one expired (X seconds from when we requested the last token, where X is given to us when we make the request. As of this writing, X is consistently 10 minutes).

Getting a Client ID and Secret

To sign up for the free tier (as of this writing), do the following:

  1. Go here
  2. Sign in with valid MSN credentials.
  3. On the right side, click 'SIGN UP', under the $0.00 option.
  4. Read and accept the terms and conditions and click the big 'SIGN UP' button.
  5. Create a new application. Fill in a unique client ID, give it a valid name, give it a valid redirect URI (not actually used by the Bing Translator API, so it can be anything) and hit 'CREATE'.
  6. Click on the name of your application to see the info again. You'll need the 'Client ID' and 'Client secret' fields.

Usage

require 'rubygems'
require 'bing_translator'
translator = BingTranslator.new('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET')
spanish = translator.translate 'Hello. This will be translated!', :from => 'en', :to => 'es'

# without :from for auto language detection
spanish = translator.translate 'Hello. This will be translated!', :to => 'es'

locale = translator.detect 'Hello. This will be translated!' # => :en

# The speak method calls a text-to-speech interface in the supplied language.
# It does not translate the text. Format can be 'audio/mp3' or 'audio/wav'

audio = translator.speak 'Hello. This will be spoken!', :language => :en, :format => 'audio/mp3', :options => 'MaxQuality'
open('file.mp3', 'wb') { |f| f.write audio }

bing_translator-gem's People

Contributors

ck3g avatar craic avatar relrod avatar unabl4 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.