• Stars
    star
    126
  • Rank 274,585 (Top 6 %)
  • Language
    HTML
  • Created almost 9 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Translator.js is a JavaScript library built top on Google Speech-Recognition & Translation API to transcript and translate voice and text. It supports many locales and brings globalization in WebRTC! https://www.webrtc-experiment.com/Translator/

Translator.js | WebRTC Voice & Text Translator

Demo: https://www.webrtc-experiment.com/Translator/

Translator.js is a JavaScript library built top on Google Speech-Recognition & Translation API to transcript and translate voice and text. It supports many locales and brings globalization in WebRTC!

How to use?

<script src="https://cdn.webrtc-experiment.com/Translator.js"> </script>

Facing issues using in your own domain?

API Reference

var translator = new Translator();

getListOfLanguages

Get list of all supported languages:

translator.getListOfLanguages(function(languages) {
    languages.forEach(function(language) {
        console.log(language.name, langauge.language);
    });
});

You can pass your API_Key as well:

var config = {
    api_key: 'AIzaSyCUmCjvKRb-kOYrnoL2xaXb8I-_JJeKpf0',
};

translator.getListOfLanguages(function(languages) {
    languages.forEach(function(language) {
        console.log(language.name, langauge.language);
    });
}, config);

translateLanguage

Pass English language text, and convert into Arabic or into any other supported language.

This method simply converts text from one language into another.

var config = {
    from: 'language-of-the-text',
    to: 'convert-into',
    api_key: 'AIzaSyCUmCjvKRb-kOYrnoL2xaXb8I-_JJeKpf0', // use your own key
    callback: function (translatedText) {
        console.log('translated text', translatedText);
        
        // here you can use "speakTextUsingRobot"
        // see below sections
    }
};

translator.translateLanguage(textToConvert, config);

translateLanguage method takes two arguments:

  1. Text to convert
  2. Source and Target Languages; also callback method

Second argument is an object.

What you can do is either display translated text in chat-box; or use speakTextUsingRobot or speakTextUsingGoogleSpeaker methods to play voice.

voiceToText

This method allows you convert voice into text; whatever you speak is recognized using Google Speech-Recognition API; and converted into text using same API:

var convertMyVoiceIntoEnglish = 'en-US'; // select any language
translator.voiceToText(function (text) {
    console.log('Your voice as text!', text);
    
    // here you can use "translateLanguage" method
    // translator.translateLanguage
    // see more info in above section
}, convertMyVoiceIntoEnglish);

voiceToText method takes two arguments:

  1. Callback; used to return recognized text
  2. Language; used to suggest Speech-Recognition API to easily recognize speaker's language

If language is not passed; then en-US will be used as default language.

You can use socket.io, websockets or any other signaling gateway like WebRTC data channels to exchange/share transcripted text with other users.

speakTextUsingRobot

Use a javascript file to speak the text.

This method uses meSpeak.js library to play text using a robot voice. Behind the scene; text is buffered and converted into WAV file; which is played using invisible <audio> element.

var config = {
    workerPath: '//cdn.webrtc-experiment.com/Robot-Speaker.js',
    callback: function (WAV_File) {},
    amplitude: 100,
    wordgap: 0,
    pitch: 50,
    speed: 175,
    onSpeakingEnd: function() {},
    onWorkerFileDownloadStart: function() {},
    onWorkerFileDownloadEnd: function() {}
};

translator.speakTextUsingRobot(textToPlay, config);

speakTextUsingRobot method accepts two arguments; first one is mandatory and last one is optional:

  1. Text to Speak i.e. convert text into voice file (WAV)
  2. Options like worker-file path etc.

Default worker file's path is https://www.webrtc-experiment.com/Robot-Speaker.js. It is strongly recommended to download and link it from your own domain.

If you want to play WAV file yourself or you want to POST/store WAV file; then you can use callback parameter to override default behaviour:

translator.speakTextUsingRobot(textToPlay, {
    callback: function (WAV_File) {
        HTTP_POST_using_FormData( WAV_File );
    }
});

onSpeakingEnd is useful in text-chat apps; where you can disable text box until text is translated and spoken; then you can enable it again.

speakTextUsingGoogleSpeaker

Use Google Servers (Translation API) to speak the text.

This method uses Google Non-Official Translation API to convert text into mp3 sound. API Key used is taken from someone on the web; and there is no guarantee of its availability; that's why it is strongly suggested to buy your own KEY and pass using api_key parameter:

translator.speakTextUsingGoogleSpeaker({
    textToSpeak: 'text-to-convert',
    targetLanguage: 'your-language',

    // Google Translation service's API Key
    api_key: 'Your-Private-API-Key'
});

Both textToSpeak and targetLanguage are mandatory. Only api_key is optional.

Use Cases

  1. You can use it in any WebRTC application to support globalization!
  2. You can use WebRTC data channels to share transcripted text among users
  3. You can mute original voice; and play translated one. Though, voice and video will NOT be sync

It is really useful in text-chat apps!

Demo

Languages Supported

102+ languages are supported. Please check above demo link for the list.

License

Translator.js is released under MIT licence . Copyright (c) Muaz Khan.

More Repositories

1

WebRTC-Experiment

WebRTC, WebRTC and WebRTC. Everything here is all about WebRTC!!
JavaScript
11,584
star
2

RecordRTC

RecordRTC is WebRTC JavaScript library for audio/video as well as screen activity recording. It supports Chrome, Firefox, Opera, Android, and Microsoft Edge. Platforms: Linux, Mac and Windows.
JavaScript
6,333
star
3

RTCMultiConnection

RTCMultiConnection is a WebRTC JavaScript library for peer-to-peer applications (screen sharing, audio/video conferencing, file sharing, media streaming etc.)
JavaScript
2,516
star
4

Chrome-Extensions

WebRTC chrome extensions for screen sharing, screen recording, file sharing, youtube+audio sharing, etc.
JavaScript
1,054
star
5

DetectRTC

DetectRTC is a tiny JavaScript library that can be used to detect WebRTC features e.g. system having speakers, microphone or webcam, screen capturing is supported, number of audio/video devices etc. https://www.webrtc-experiment.com/DetectRTC/
JavaScript
651
star
6

WebRTC-Scalable-Broadcast

This module simply initializes socket.io and configures it in a way that single broadcast can be relayed over unlimited users without any bandwidth/CPU usage issues. Everything happens peer-to-peer!
JavaScript
530
star
7

Ffmpeg.js

Ffmpeg.js demos, both for browsers and node.js
JavaScript
481
star
8

MultiStreamsMixer

MultiStreamsMixer is a JavaScript library that allows you pass multiple streams (e.g. screen+camera or multiple-cameras) and get single stream.
JavaScript
414
star
9

Canvas-Designer

Collaborative, extendable, JavaScript Canvas2D drawing tool, supports dozens of builtin tools, as well as generates JavaScript code for 2D animations.
JavaScript
359
star
10

RTCMultiConnection-Server

RTCMultiConnection socket.io server (npm install rtcmulticonnection-server)
JavaScript
266
star
11

getStats

getStats is a tiny JavaScript library using WebRTC getStats API to return peer connection stats i.e. bandwidth usage, packets lost, local/remote ip addresses and ports, type of connection etc.
JavaScript
256
star
12

FileBufferReader

FileBufferReader is a JavaScript library reads file and returns chunkified array-buffers. The resulting buffers can be shared using WebRTC data channels or socket.io.
JavaScript
66
star
13

getScreenId

getScreenId | Capture Screen on Any Domain! This script is a hack used to support single chrome extension usage on any HTTPs domain.
HTML
63
star
14

MultiRTC

A skype-like RTCMultiConnection demo application.
JavaScript
62
star
15

DataChannel

DataChannel.js is a JavaScript library useful to write many-to-many i.e. group file/data sharing or text chat applications. Its syntax is easier to use and understand. It highly simplifies complex tasks like any or all user rejection/ejection; direct messages delivery; and more.
JavaScript
58
star
16

Conversation.js

Conversation.js is inspired by skype; and it provides simple events-like API to manage conversations, enable/disable media devices; add/download files; and do anything supported by Skype. It allows you open data conversation between two or more users using their user-ids.
JavaScript
49
star
17

Firefox-Extensions

(discontinued) Firefox extension API are used to enable screen capturing flag for your own domains!
JavaScript
45
star
18

WebSync-Signaling

WebSync is used as signaling gateway with/for WebRTC-Experiments e.g. RTCMultiConnection.js, DataChannel.js, Plugin-free screen sharing, and video conferencing.
JavaScript
43
star
19

ConcatenateBlobs

Simply pass array of blobs. This javascript library will concatenate all blobs in single Blob object.
HTML
40
star
20

WebRTC-ASPNET-MVC

A simple WebRTC one-to-one demo written in September, 2012! It supports public rooms as well as password-protected private rooms! MS-SQL database is used as signaling gateway!
JavaScript
38
star
21

XHR-Signaling

XHR/XMLHttpRequest based WebRTC signaling implementation.
C#
37
star
22

Reliable-Signaler

A reliable socketlio/node.js based signaling implementation for DataChannel.js, RTCMultiConnection.js and WebRTC Experiments.
JavaScript
32
star
23

RTCMultiConnection-SignalR

SignalR project for RTCMultiConnection
JavaScript
21
star
24

Everything

Everything from Muaz Khan — HTML5, CSS3, JavaScript, WebRTC, WebGL, Canvas2D, SVG, etc.
JavaScript
18
star
25

Curvature

Curvature is a tool lets you design bezier curves using Canvas 2d APIs!
JavaScript
17
star