Skip to content

Instantly share code, notes, and snippets.

@jswhisperer
Forked from karthikshiraly/myapp.html
Created February 17, 2014 20:53
Show Gist options
  • Select an option

  • Save jswhisperer/9058896 to your computer and use it in GitHub Desktop.

Select an option

Save jswhisperer/9058896 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Backbone.js example</title>
<link rel="stylesheet" type="text/css" href="css/sunny/jqueryui.min.css"/>
</head>
<body>
<!-- "slider" is a jquery slider -->
<div id="slider"></div>
<!-- "sliderVal" displays the slider's position. It receives the value via model. -->
<input type="text" id="sliderVal" value="0"/>
<script type="text/javascript" language="Javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" language="Javascript" src="js/underscore-min.js"></script>
<script type="text/javascript" language="Javascript" src="js/backbone-min.js"></script>
<script type="text/javascript" language="Javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
<script type="text/javascript" language="Javascript" src="js/myapp.js"></script>
</body>
</html>
$(document).ready(function() {
// Initialize jquery slider
$("#slider").slider();
// Create the model class via Backbone (which sets up things like prototype objects correctly).
// This particular model is a very simple one. It'll have just 1 attribute - "slidervalue"
var SliderModel = Backbone.Model.extend({});
// A "View" abstraction for the slider.
// Whenever the slider position changes, this view updates the model with the new value.
var SliderView = Backbone.View.extend({
el : $("#slider"), // Specifies the DOM element which this view handles
events : {
// Call the event handler "updateVal" when slider value changes.
// 'slidechange' is the jquery slider widget's event type.
// Refer http://jqueryui.com/demos/slider/#default for information about 'slidechange'.
"slidechange" : "updateVal"
},
updateVal : function() {
// Get slider value and set it in model using model's 'set' method.
console.log('SliderView.updateVal');
var val = this.el.slider("option", "value");
this.model.set({slidervalue : val});
}
});
// The listener "View" for the model.
// Whenever the model's slidervalue attribute changes, this view receives the updated value.
var ValueView = Backbone.View.extend({
initialize: function(args) {
// _.bindAll is provided by underscore.js.
// Due to some javascript quirks, event handlers which are bound receive a 'this'
// value which is "useless" (according to underscore's docs).
// _.bindAll is a hack that ensures that 'this' in event handler refers to this view.
_.bindAll(this, 'updateValue');
console.log('ValueView.initialize');
// Bind an event handler to receive updates from the model whenever its
// 'slidervalue' attribute changes.
this.model.bind('change:slidervalue', this.updateValue);
console.log(this);
},
updateValue: function() {
// Get the slider value from model, and display it in textbox.
console.log('ValueView.updateValue');
// this.model won't work unless "_.bindAll(this, ...)" has been called in initialize
var value = this.model.get('slidervalue');
console.log(value);
$("#sliderVal").val(value);
}
});
// Create the instances
var sliderModel = new SliderModel;
var sliderView = new SliderView({model : sliderModel});
var valView = new ValueView({model : sliderModel});
});
@chandruak842-droid

Copy link
Copy Markdown
<title>தமிழ் குரல் ஆப்</title> <style> body { font-family: sans-serif; text-align: center; padding: 20px; background-color: #f0f4f8; } h2 { color: #2c3e50; } .btn-mic { background-color: #e74c3c; color: white; border: none; padding: 15px 25px; font-size: 18px; border-radius: 30px; margin-bottom: 15px; width: 90%; } textarea { width: 90%; height: 70px; margin: 10px 0; padding: 10px; font-size: 16px; border-radius: 8px; border: 1px solid #ccc; } .btn-lang { background-color: #27ae60; color: white; border: none; padding: 12px; font-size: 16px; border-radius: 8px; margin: 5px; width: 42%; } </style>
<h2>🗣️ தமிழ் குரல் ஆப்</h2>

<button class="btn-mic" onclick="startRecognition()">🎤 பேச தொடங்குங்கள்</button>

<textarea id="tamilText" placeholder="நீங்கள் பேசுவது இங்கே தோன்றும்..."></textarea>
<textarea id="translatedText" placeholder="மொழிபெயர்ப்பு இங்கே தோன்றும்..." readonly></textarea>

<h3>மொழியைத் தேர்ந்தெடுக்கவும்:</h3>
<button class="btn-lang" onclick="translateAndSpeak('te', 'te-IN')">🇮🇳 தெலுங்கு</button>
<button class="btn-lang" onclick="translateAndSpeak('hi', 'hi-IN')">🇮🇳 ஹிந்தி</button>
<button class="btn-lang" onclick="translateAndSpeak('kn', 'kn-IN')">🇮🇳 கன்னடம்</button>
<button class="btn-lang" onclick="translateAndSpeak('ml', 'ml-IN')">🇮🇳 மலையாளம்</button>
<button class="btn-lang" onclick="translateAndSpeak('en', 'en-US')" style="width: 88%;">🇬🇧 English</button>

<script>
    const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
    let recognition = SpeechRecognition ? new SpeechRecognition() : null;

    if (recognition) {
        recognition.lang = 'ta-IN';
        recognition.onresult = function(event) {
            document.getElementById('tamilText').value = event.results[0][0].transcript;
        };
    }

    function startRecognition() {
        if (recognition) recognition.start();
        else alert("Voice recognition support இல்லை.");
    }

    async function translateAndSpeak(targetLang, synthLang) {
        const text = document.getElementById('tamilText').value;
        if (!text) return alert("முதலில் பேசவும்!");

        const url = `https://translate.googleapis.com/translate_a/single?client=gtx&sl=ta&tl=${targetLang}&dt=t&q=${encodeURIComponent(text)}`;
        try {
            const response = await fetch(url);
            const result = await response.json();
            const translated = result[0][0][0];
            document.getElementById('translatedText').value = translated;

            const utterance = new SpeechSynthesisUtterance(translated);
            utterance.lang = synthLang;
            window.speechSynthesis.speak(utterance);
        } catch (e) {
            alert("பிழை ஏற்பட்டது.");
        }
    }
</script>

@chandruak842-droid

Copy link
Copy Markdown
<title>தமிழ் குரல் ஆப்</title> <style> body { font-family: sans-serif; text-align: center; padding: 20px; background-color: #f0f4f8; } h2 { color: #2c3e50; } .btn-mic { background-color: #e74c3c; color: white; border: none; padding: 15px 25px; font-size: 18px; border-radius: 30px; margin-bottom: 15px; width: 90%; } textarea { width: 90%; height: 70px; margin: 10px 0; padding: 10px; font-size: 16px; border-radius: 8px; border: 1px solid #ccc; } .btn-lang { background-color: #27ae60; color: white; border: none; padding: 12px; font-size: 16px; border-radius: 8px; margin: 5px; width: 42%; } </style>
<h2>🗣️ தமிழ் குரல் ஆப்</h2>

<button class="btn-mic" onclick="startRecognition()">🎤 பேச தொடங்குங்கள்</button>

<textarea id="tamilText" placeholder="நீங்கள் பேசுவது இங்கே தோன்றும்..."></textarea>
<textarea id="translatedText" placeholder="மொழிபெயர்ப்பு இங்கே தோன்றும்..." readonly></textarea>

<h3>மொழியைத் தேர்ந்தெடுக்கவும்:</h3>
<button class="btn-lang" onclick="translateAndSpeak('te', 'te-IN')">🇮🇳 தெலுங்கு</button>
<button class="btn-lang" onclick="translateAndSpeak('hi', 'hi-IN')">🇮🇳 ஹிந்தி</button>
<button class="btn-lang" onclick="translateAndSpeak('kn', 'kn-IN')">🇮🇳 கன்னடம்</button>
<button class="btn-lang" onclick="translateAndSpeak('ml', 'ml-IN')">🇮🇳 மலையாளம்</button>
<button class="btn-lang" onclick="translateAndSpeak('en', 'en-US')" style="width: 88%;">🇬🇧 English</button>

<script>
    const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
    let recognition = SpeechRecognition ? new SpeechRecognition() : null;

    if (recognition) {
        recognition.lang = 'ta-IN';
        recognition.onresult = function(event) {
            document.getElementById('tamilText').value = event.results[0][0].transcript;
        };
    }

    function startRecognition() {
        if (recognition) recognition.start();
        else alert("Voice recognition support இல்லை.");
    }

    async function translateAndSpeak(targetLang, synthLang) {
        const text = document.getElementById('tamilText').value;
        if (!text) return alert("முதலில் பேசவும்!");

        const url = `https://translate.googleapis.com/translate_a/single?client=gtx&sl=ta&tl=${targetLang}&dt=t&q=${encodeURIComponent(text)}`;
        try {
            const response = await fetch(url);
            const result = await response.json();
            const translated = result[0][0][0];
            document.getElementById('translatedText').value = translated;

            const utterance = new SpeechSynthesisUtterance(translated);
            utterance.lang = synthLang;
            window.speechSynthesis.speak(utterance);
        } catch (e) {
            alert("பிழை ஏற்பட்டது.");
        }
    }
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment