What are the languages supported by Web speech API? - google-chrome
I plan to convert text to speech on certain events. What are the languages supported by the Web Speech API?
Web speech API
In one old thread, I found the information that below languages are supported.
var langs =
[['Afrikaans', ['af-ZA']],
['Bahasa Indonesia',['id-ID']],
['Bahasa Melayu', ['ms-MY']],
['Català', ['ca-ES']],
['Čeština', ['cs-CZ']],
['Deutsch', ['de-DE']],
['English', ['en-AU', 'Australia'],
['en-CA', 'Canada'],
['en-IN', 'India'],
['en-NZ', 'New Zealand'],
['en-ZA', 'South Africa'],
['en-GB', 'United Kingdom'],
['en-US', 'United States']],
['Español', ['es-AR', 'Argentina'],
['es-BO', 'Bolivia'],
['es-CL', 'Chile'],
['es-CO', 'Colombia'],
['es-CR', 'Costa Rica'],
['es-EC', 'Ecuador'],
['es-SV', 'El Salvador'],
['es-ES', 'España'],
['es-US', 'Estados Unidos'],
['es-GT', 'Guatemala'],
['es-HN', 'Honduras'],
['es-MX', 'México'],
['es-NI', 'Nicaragua'],
['es-PA', 'Panamá'],
['es-PY', 'Paraguay'],
['es-PE', 'Perú'],
['es-PR', 'Puerto Rico'],
['es-DO', 'República Dominicana'],
['es-UY', 'Uruguay'],
['es-VE', 'Venezuela']],
['Euskara', ['eu-ES']],
['Français', ['fr-FR']],
['Galego', ['gl-ES']],
['Hrvatski', ['hr_HR']],
['IsiZulu', ['zu-ZA']],
['Íslenska', ['is-IS']],
['Italiano', ['it-IT', 'Italia'],
['it-CH', 'Svizzera']],
['Magyar', ['hu-HU']],
['Nederlands', ['nl-NL']],
['Norsk bokmål', ['nb-NO']],
['Polski', ['pl-PL']],
['Português', ['pt-BR', 'Brasil'],
['pt-PT', 'Portugal']],
['Română', ['ro-RO']],
['Slovenčina', ['sk-SK']],
['Suomi', ['fi-FI']],
['Svenska', ['sv-SE']],
['Türkçe', ['tr-TR']],
['български', ['bg-BG']],
['Pусский', ['ru-RU']],
['Српски', ['sr-RS']],
['한국어', ['ko-KR']],
['中文', ['cmn-Hans-CN', '普通话 (中国大陆)'],
['cmn-Hans-HK', '普通话 (香港)'],
['cmn-Hant-TW', '中文 (台灣)'],
['yue-Hant-HK', '粵語 (香港)']],
['日本語', ['ja-JP']],
['Lingua latīna', ['la']]];
Web Speech API Demonstration
Reference:
What are the supported languages for Web Speech API in HTML5?
I suggest you also check the browser compatibility of web speech API.
The voices supported depend on the browser and operating system. This has evolved over time as more voices are added.
I wrote a JSBin that displays a browser's voices in that OS: https://output.jsbin.com/dehoyavize
"use strict";
/** Draw table from array of objects **/
const drawTable = (obArr, tableDiv) => {
const table = document.createElement('table');
// Table header row
const thr = document.createElement('tr');
for (const p in obArr[0]) {
// Get column headers from voice attributes
const th = document.createElement('th');
th.appendChild(document.createTextNode(p));
thr.appendChild(th);
}
table.appendChild(thr);
// Build rows
for (const obj of obArr) {
const tr = document.createElement('tr');
for (const p in obj) {
// Build table from each voice's attribute values
const td = document.createElement('td');
td.appendChild(document.createTextNode(obj[p]));
tr.appendChild(td);
}
table.appendChild(tr);
};
// Add table to document
tableDiv.appendChild(table);
};
/** get w3c voices **/
if ('speechSynthesis' in window) {
const tableDiv = document.querySelector('#tableDiv');
let voices = speechSynthesis.getVoices();
if (voices.length) {
// Safari; FF caches voices after 1st load
drawTable(voices, tableDiv);
} else {
// Opera win, Firefox 1st load, Chrome
speechSynthesis.onvoiceschanged = () => {
voices = speechSynthesis.getVoices();
drawTable(voices, tableDiv);
};
}
} else {
// No window.speechSynthesis thus no voices
// Opera android, etc.
document.querySelector('#tableDiv').innerText = 'This browser has no voices';
}
table, td, th {
border: 1px solid black;
font-family: sans-serif;
}
tr:nth-child(even) {
background-color: #eee;
}
<body>
<div id="tableDiv">
</div>
</body>
Related
Audio Level Meter for Web RTC Stream
I would like to create a decibel meter for the audio that is playing in a video element. The video element is playing a WebRTC stream. At the moment WebRTC streams cannot be passed into a Web Audio Analyzer. (Although this might change soon … ) (see Web Audio API analyser node getByteFrequencyData returning blank array) Is there currently another way to get decibel information from a remote mediastream?
Chrome 50 was released: As of the 13th of April 2016 using an Analyser Node with a MediaStreamAudioSourceNode works fine to get audio levels. The resulting audioLevels value can be animated or simply passed into a html meter element. var _mediaStream = SOME_LOCAL_OR_RTP_MEDIASTREAM; var _audioContext = new AudioContext(); var _audioAnalyser = []; var _freqs = []; var audioLevels = [0]; var _audioSource = _audioContext.createMediaStreamSource(_mediaStream); var _audioGain1 = _audioContext.createGain(); var _audioChannelSplitter = _audioContext.createChannelSplitter(_audioSource.channelCount); _audioSource.connect(_audioGain1); _audioGain1.connect(_audioChannelSplitter); _audioGain1.connect(_audioContext.destination); for (let i = 0; i < _audioSource.channelCount; i++) { _audioAnalyser[i] = _audioContext.createAnalyser(); _audioAnalyser[i].minDecibels = -100; _audioAnalyser[i].maxDecibels = 0; _audioAnalyser[i].smoothingTimeConstant = 0.8; _audioAnalyser[i].fftSize = 32; _freqs[i] = new Uint8Array(_audioAnalyser[i].frequencyBinCount); _audioChannelSplitter.connect(_audioAnalyser[i], i, 0); } function calculateAudioLevels() { setTimeout(() => { for (let channelI = 0; channelI < _audioAnalyser.length; channelI++) { _audioAnalyser[channelI].getByteFrequencyData(_freqs[channelI]); let value = 0; for (let freqBinI = 0; freqBinI < _audioAnalyser[channelI].frequencyBinCount; freqBinI++) { value = Math.max(value, _freqs[channelI][freqBinI]); } audioLevels[channelI] = value / 256; } requestAnimationFrame(calculateAudioLevels.bind(this)); }, 1000 / 15); // Max 15fps — not more needed }
This is a good example: https://webrtc.github.io/samples/src/content/getusermedia/volume/ And this is the source code: https://github.com/webrtc/samples/tree/gh-pages/src/content/getusermedia/volume And this is a sample: function recordAudio() { try { window.AudioContext = window.AudioContext || window.webkitAudioContext; window.audioContext = new AudioContext(); const instantMeter = document.querySelector('#sound-meter'); const constraints = {'video': false, 'audio': true}; const stream = await navigator.mediaDevices.getUserMedia(constraints); window.stream = stream; const soundMeter = window.soundMeter = new SoundMeter(window.audioContext); soundMeter.connectToSource(stream, function(e) { if (e) { alert(e); return; } setInterval(() => { instantMeter.value = soundMeter.instant.toFixed(2); }, 200); }); $('#sound-meter').show(); $('#audio-icon').hide() } catch(error) { console.error('Error recording audio.', error); } }
Is there a way to lower the recording volume of HTML5 recording to prevent feedback?
I am using Recorder.js to record audio but there is terrible feedback if I don't use a headset. There is even a little feedback if I use my apple earphones where the mic is a bit closer to the ear piece. Is there a way to lower the mic/recording volume and prevent the feedback?
If you have access to the gain_node - you can control the output speaker volume put this into your html (optional) <p>Volume</p> <input id="volume" type="range" min="0" max="1" step="0.1" value="0.5"/> then do similar to following where U have access to the gain_node document.getElementById('volume').addEventListener('change', function() { var curr_volume = this.value; gain_node.gain.value = curr_volume; console.log("curr_volume ", curr_volume); }); below I bundle above into a set of calls to Web Audio API where I have a UI widget to change the volume while it listens to your microphone ... turn DOWN your volume before running this ! <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>capture microphone then show time & frequency domain output</title> <script type="text/javascript"> var webaudio_tooling_obj = function () { var audioContext = new AudioContext(); console.log("audio is starting up ..."); var BUFF_SIZE_RENDERER = 16384; var SIZE_SHOW = 3; // number of array elements to show in console output var audioInput = null, microphone_stream = null, gain_node = null, script_processor_node = null, script_processor_analysis_node = null, analyser_node = null; if (!navigator.getUserMedia) navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; if (navigator.getUserMedia){ navigator.getUserMedia({audio:true}, function(stream) { start_microphone(stream); }, function(e) { alert('Error capturing audio.'); } ); } else { alert('getUserMedia not supported in this browser.'); } // --- function show_some_data(given_typed_array, num_row_to_display, label) { var size_buffer = given_typed_array.length; var index = 0; console.log("__________ " + label); if (label === "time") { for (; index < num_row_to_display && index < size_buffer; index += 1) { var curr_value_time = (given_typed_array[index] / 128) - 1.0; console.log(curr_value_time); } } else if (label === "frequency") { for (; index < num_row_to_display && index < size_buffer; index += 1) { console.log(given_typed_array[index]); } } else { throw new Error("ERROR - must pass time or frequency"); } } function process_microphone_buffer(event) { var i, N, inp, microphone_output_buffer; // not needed for basic feature set // microphone_output_buffer = event.inputBuffer.getChannelData(0); // just mono - 1 channel for now } function start_microphone(stream){ gain_node = audioContext.createGain(); gain_node.connect( audioContext.destination ); microphone_stream = audioContext.createMediaStreamSource(stream); microphone_stream.connect(gain_node); script_processor_node = audioContext.createScriptProcessor(BUFF_SIZE_RENDERER, 1, 1); script_processor_node.onaudioprocess = process_microphone_buffer; microphone_stream.connect(script_processor_node); // --- enable volume control for output speakers document.getElementById('volume').addEventListener('change', function() { var curr_volume = this.value; gain_node.gain.value = curr_volume; console.log("curr_volume ", curr_volume); }); // --- setup FFT script_processor_analysis_node = audioContext.createScriptProcessor(2048, 1, 1); script_processor_analysis_node.connect(gain_node); analyser_node = audioContext.createAnalyser(); analyser_node.smoothingTimeConstant = 0; analyser_node.fftSize = 2048; microphone_stream.connect(analyser_node); analyser_node.connect(script_processor_analysis_node); var buffer_length = analyser_node.frequencyBinCount; var array_freq_domain = new Uint8Array(buffer_length); var array_time_domain = new Uint8Array(buffer_length); console.log("buffer_length " + buffer_length); script_processor_analysis_node.onaudioprocess = function() { // get the average for the first channel analyser_node.getByteFrequencyData(array_freq_domain); analyser_node.getByteTimeDomainData(array_time_domain); // draw the spectrogram if (microphone_stream.playbackState == microphone_stream.PLAYING_STATE) { show_some_data(array_freq_domain, SIZE_SHOW, "frequency"); show_some_data(array_time_domain, SIZE_SHOW, "time"); // store this to record to aggregate buffer/file } }; } }(); // webaudio_tooling_obj = function() </script> </head> <body> <p>Volume</p> <input id="volume" type="range" min="0" max="1" step="0.1" value="0.0"/> </body> </html> Of course no UI widget is necessary as you have programmatic control over the output volume and so to go silent you can either disconnect the gain node or just set it low
Their example page (example_simple_exportwav.html) states that you should wear headphones or turn down the volume. Also before you enable microphone input either plug in headphones or turn the volume down if you want to avoid ear splitting feedback! You could mute or decrease the volume of the speakers during recording: Muting a HTML5 audio element using a custom button How to mute all sound in a page with JS? How to set the loudness of HTML5 audio? I also tested a few examples and never experienced feedback with my laptop speakers. Could you post your code so we could test it live? Record and Export Audio, Video files in browser using Web Audio API with Recorder.js - demo at the bottom http://webaudiodemos.appspot.com/AudioRecorder/index.html via Web Audio Demos
How to Read a text file using Java script and display it in column fashion in HTML.?
This is the code which reads the text file using the Jscript and displays it in HTML. But i need it to display it in table. How to display it in Table. < this is my first question so i hope i get solution > ` Read File (via User Input selection) var reader; //GLOBAL File Reader object for demo purpose only /** * Check for the various File API support. */ function checkFileAPI() { if (window.File && window.FileReader && window.FileList && window.Blob) { reader = new FileReader(); return true; } else { alert('The File APIs are not fully supported by your browser. Fallback required.'); return false; } } /** * read text input */ function readText(filePath) { var output = ""; //placeholder for text output if(filePath.files && filePath.files[0]) { reader.onload = function (e) { output = e.target.result; displayContents(output); };//end onload() reader.readAsText(filePath.files[0]); }//end if html5 filelist support else if(ActiveXObject && filePath) { //fallback to IE 6-8 support via ActiveX try { reader = new ActiveXObject("Scripting.FileSystemObject"); var file = reader.OpenTextFile(filePath, 1); //ActiveX File Object output = file.ReadAll(); //text contents of file file.Close(); //close file "input stream" displayContents(output); } catch (e) { if (e.number == -2146827859) { alert('Unable to access local files due to browser security settings. ' + 'To overcome this, go to Tools->Internet Options->Security->Custom Level. ' + 'Find the setting for "Initialize and script ActiveX controls not marked as safe" and change it to "Enable" or "Prompt"'); } } } else { //this is where you could fallback to Java Applet, Flash or similar return false; } return true; } /** * display content using a basic HTML replacement */ function displayContents(txt) { var el = document.getElementById('main'); el.innerHTML = txt; //display output in DOM } </script> </head> <body onload="checkFileAPI();"> <div id="container"> <input type="file" onchange='readText(this)' /> <br/> <hr/> <h3>Contents of the Text file:</h3> <div id="main"> ... </div> </div> </body> </html>` Please help me in this
You could format the text file like a SSV (TSV or CSV as well), then instead of ReadAll() I'd do something like this: var file = reader.OpenTextFile(filePath, 1), data = [], n; while (!file.AtEndOfStream) { data.push(file.ReadLine().split(';')); // or use some other "cell-separator" } Then the rest is a lot simpler and faster, if you've an empty table element in your HTML: <table id="table"></table> Now just create rows and cells dynamically based on the data array: var table = document.getElementById('table'), len = data.length, r, row, c, cell; for (r = 0; r < len; r++) { row = table.insertRow(-1); for (c = 0; c < data[r].lenght; r++) { cell.row.insertCell(-1); cell.innerHTML = data[r][c]; } }
Is possible create map html area in percentage?
I need to create something like this: http://www.mrporter.com/journal/journal_issue71/2#2 where every product in my big image is associated with a tooltip which appears on mouse hover. But I need this to work with fullscreen images. The first solution I thought (as the example above) is the map html solution where each fill up exactly the boundaries of my products. The problem is that I can't indicate precise values for my because my image size depends on window screen. The best solution would be the possibility to set percentage values for my area. Is this possible? Any other suggestions ?
Alternative solution using links: CSS: .image{ position: relative; } .image a{ display: block; position: absolute; } HTML: <div class="image"> <img src="image.jpg" alt="image" /> </div> Percentage dimensions can be detected in graphic editors
There is a jQuery plugin for this jQuery RWD Image Maps. You might want to integrate my pending pull request (manually) to support "width=100%": https://github.com/stowball/jQuery-rwdImageMaps/pull/10
you can check this this plugin is life saving. Useful when you want to map a percentage scaled image etc. It can be used with or without jQuery. https://github.com/davidjbradshaw/imagemap-resizer and you can see it working at. http://davidjbradshaw.com/imagemap-resizer/example/
Because this can't be done with simple HTML/CSS manipulation, the only alternative is JavaScript to, effectively, recalculate the coordinates based on the resizing of the image. To this end I've put together a function (though there's two functions involved) that achieves this end: function findSizes(el, src) { if (!el || !src) { return false; } else { var wGCS = window.getComputedStyle, pI = parseInt, dimensions = {}; dimensions.actualWidth = pI(wGCS(el, null).width.replace('px', ''), 10); var newImg = document.createElement('img'); newImg.src = src; newImg.style.position = 'absolute'; newImg.style.left = '-10000px'; document.body.appendChild(newImg); dimensions.originalWidth = newImg.width; document.body.removeChild(newImg); return dimensions; } } function remap(imgElem) { if (!imgElem) { return false; } else { var mapName = imgElem .getAttribute('usemap') .substring(1), map = document.getElementsByName(mapName)[0], areas = map.getElementsByTagName('area'), imgSrc = imgElem.src, sizes = findSizes(imgElem, imgSrc), currentWidth = sizes.actualWidth, originalWidth = sizes.originalWidth, multiplier = currentWidth / originalWidth, newCoords; for (var i = 0, len = areas.length; i < len; i++) { newCoords = areas[i] .getAttribute('coords') .replace(/(\d+)/g,function(a){ return Math.round(a * multiplier); }); areas[i].setAttribute('coords',newCoords); } } } var imgElement = document.getElementsByTagName('img')[0]; remap(imgElement); JS Fiddle demo. Please note, though, that this requires a browser that implements window.getComputedStyle() (most current browsers, but only in IE from version 9, and above). Also, there are no sanity checks other than ensuring the required arguments are passed into the functions. These should, though, be a start if you want to experiment. References: document.body. document.createElement(). document.getElementsByName(). document.getElementsByTagName(). element.getAttribute(). element.setAttribute(). element.style. Math.round(). node.appendChild(). node.removeChild(). parseInt(). string.replace(). string.substring(). window.getComputedStyle.
Percentages in image maps are not an option. You might want to get some scripting involved (JS) that recalculates the exact position on images resize. Of course, in that script you can work with percentages if you want.
Consider using the Raphaël JavaScript Library with some CSS. See http://raphaeljs.com/ and Drawing over an image using Raphael.js.
I know this is an old question but maybe someone needs this at some point as I did. I modified #David Thomas' answer a bit to be have this little piece of JS be able to handle future recalculations: function findSizes(el, src) { if (!el || !src) { return false; } else { var wGCS = window.getComputedStyle, pI = parseInt, dimensions = {}; dimensions.actualWidth = pI(wGCS(el, null).width.replace('px', ''), 10); var newImg = document.createElement('img'); newImg.src = src; newImg.style.position = 'absolute'; newImg.style.left = '-10000px'; document.body.appendChild(newImg); dimensions.originalWidth = newImg.width; document.body.removeChild(newImg); return dimensions; } } function remap(imgElem) { if (!imgElem) { return false; } else { var mapName = imgElem .getAttribute('usemap') .substring(1), map = document.getElementsByName(mapName)[0], areas = map.getElementsByTagName('area'), imgSrc = imgElem.src, sizes = findSizes(imgElem, imgSrc), currentWidth = sizes.actualWidth, originalWidth = sizes.originalWidth, multiplier = currentWidth / originalWidth, newCoords; for (var i = 0, len = areas.length; i < len; i++) { // Save original coordinates for future use var originalCoords = areas[i].getAttribute('data-original-coords'); if (originalCoords == undefined) { originalCoords = areas[i].getAttribute('coords'); areas[i].setAttribute('data-original-coords', originalCoords); } newCoords = originalCoords.replace(/(\d+)/g,function(a){ return Math.round(a * multiplier); }); areas[i].setAttribute('coords',newCoords); } } } function remapImage() { var imgElement = document.getElementsByTagName('img')[0]; remap(imgElement); } // Add a window resize event listener var addEvent = function(object, type, callback) { if (object == null || typeof(object) == 'undefined') return; if (object.addEventListener) { object.addEventListener(type, callback, false); } else if (object.attachEvent) { object.attachEvent("on" + type, callback); } else { object["on"+type] = callback; } }; addEvent(window, "resize", remapImage);
How to embed a progressbar into a HTML form?
I have this code below and want it to show the progress of a form submission of a file upload. I want it to work on my website visit it through this IP (24.148.156.217). So if you saw the website I want the progress bar to be displayed when the user fills in the information and then hits the submit button. Then the progress bar displays with the time until it's finished. <style> <!-- .hide { position:absolute; visibility:hidden; } .show { position:absolute; visibility:visible; } --> </style> <SCRIPT LANGUAGE="JavaScript"> //Progress Bar script- by Todd King (tking#igpp.ucla.edu) //Modified by JavaScript Kit for NS6, ability to specify duration //Visit JavaScript Kit (http://javascriptkit.com) for script var duration=3 // Specify duration of progress bar in seconds var _progressWidth = 50; // Display width of progress bar. var _progressBar = "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" var _progressEnd = 5; var _progressAt = 0; // Create and display the progress dialog. // end: The number of steps to completion function ProgressCreate(end) { // Initialize state variables _progressEnd = end; _progressAt = 0; // Move layer to center of window to show if (document.all) { // Internet Explorer progress.className = 'show'; progress.style.left = (document.body.clientWidth/2) - (progress.offsetWidth/2); progress.style.top = document.body.scrollTop+(document.body.clientHeight/2) - (progress.offsetHeight/2); } else if (document.layers) { // Netscape document.progress.visibility = true; document.progress.left = (window.innerWidth/2) - 100+"px"; document.progress.top = pageYOffset+(window.innerHeight/2) - 40+"px"; } else if (document.getElementById) { // Netscape 6+ document.getElementById("progress").className = 'show'; document.getElementById("progress").style.left = (window.innerWidth/2)- 100+"px"; document.getElementById("progress").style.top = pageYOffset+(window.innerHeight/2) - 40+"px"; } ProgressUpdate(); // Initialize bar } // Hide the progress layer function ProgressDestroy() { // Move off screen to hide if (document.all) { // Internet Explorer progress.className = 'hide'; } else if (document.layers) { // Netscape document.progress.visibility = false; } else if (document.getElementById) { // Netscape 6+ document.getElementById("progress").className = 'hide'; } } // Increment the progress dialog one step function ProgressStepIt() { _progressAt++; if(_progressAt > _progressEnd) _progressAt = _progressAt % _progressEnd; ProgressUpdate(); } // Update the progress dialog with the current state function ProgressUpdate() { var n = (_progressWidth / _progressEnd) * _progressAt; if (document.all) { // Internet Explorer var bar = dialog.bar; } else if (document.layers) { // Netscape var bar = document.layers["progress"].document.forms["dialog"].bar; n = n * 0.55; // characters are larger } else if (document.getElementById){ var bar=document.getElementById("bar") } var temp = _progressBar.substring(0, n); bar.value = temp; } // Demonstrate a use of the progress dialog. function Demo() { ProgressCreate(10); window.setTimeout("Click()", 100); } function Click() { if(_progressAt >= _progressEnd) { ProgressDestroy(); return; } ProgressStepIt(); window.setTimeout("Click()", (duration-1)*1000/10); } function CallJS(jsStr) { //v2.0 return eval(jsStr) } </script> <SCRIPT LANGUAGE="JavaScript"> // Create layer for progress dialog document.write("<span id=\"progress\" class=\"hide\">"); document.write("<FORM name=dialog id=dialog>"); document.write("<TABLE border=2 bgcolor=\"#FFFFCC\">"); document.write("<TR><TD ALIGN=\"center\">"); document.write("Progress<BR>"); document.write("<input type=text name=\"bar\" id=\"bar\" size=\"" + _progressWidth/2 + "\""); if(document.all||document.getElementById) // Microsoft, NS6 document.write(" bar.style=\"color:navy;\">"); else // Netscape document.write(">"); document.write("</TD></TR>"); document.write("</TABLE>"); document.write("</FORM>"); document.write("</span>"); ProgressDestroy(); // Hides </script> <form name="form1" method="post"> <center> <input type="button" name="Demo" value="Display progress" onClick="CallJS('Demo()')"> </center> </form> Text link example
JQuery UI has a progress bar feature. This is a purely CSS progress bar that works on most browsers including IE6.
If using Flash is okay for you, you could try SWFUpload.