Microsoft Sapi in Javascript - changing voices - javascript

Currently working on an implementation to use SAPI object in javascript to render some text to speech.
I have basic code which works as:
VoiceObj = new ActiveXObject("Sapi.SpVoice");
VoiceObj.Speak("hello world");
I am now looking at a way to change which voice is getting used for the TTS. From looking through the SAPI docs online, I have managed to get an object which contains the voices available, and can select them by an index.
voices = VoiceObj.GetVoices();
VoiceObj.Voice = voices.Item(1);
console.log(VoiceObj.Voice.GetDescription());
This will correctly pulls voices back, and when logged out, will give the name of the voice. The problem comes when I try and call .Speak after making a change to the voice. The javascript will just throw Automation server can't create object error and no speech is heard.
Is this the correct way for changing the voice? I can not find any other methods available which would achieve this.

var voiceObj = new ActiveXObject("Sapi.SpVoice");
//voiceObj.Speak("hello world");
var voices = voiceObj.GetVoices();
var i,n=voices.Count;
var v; //VoiceObj.Voice
for(i=0; i<n; i++){
console.log("Item "+i);
var v=voices.Item(i);
console.log(v.GetDescription());
}

Related

Add Checkbox/DropDownList in WORD using Addin JS API

I'm new to WORD ADDIN and I want to add Checkbox/DropDownList in MS WORD using Word Addin and I tried to add using Word.ContentControlType but its not helping. Can anybody tell me or provide any reference regarding it? I'm sharing my code along with the link to the official documentation of WORD ADDIN JAVASCRIPT API.
Thanks.
document.getElementById("btn-1").addEventListener("click", ()=>{
Word.run(function (context) {
var range = context.document.getSelection();
// var myContentControl = range.insertContentControl();
var myContentControl = range.insertContentControl(Word.ContentControlType.checkBox);
myContentControl.tag = 'FirstName';
myContentControl.title = 'FirstName';
myContentControl.cannotEdit = false;
// myContentControl.style = 'Heading 2';
myContentControl.insertText('');
myContentControl.appearance = Word.ContentControlAppearance.boundingBox;
context.load(myContentControl, 'id');
return context.sync().then(function () {});
});
});
https://learn.microsoft.com/en-us/javascript/api/word/word.contentcontroltype?view=word-js-preview
Thank you for reaching us! Checkbox and DropDownList content control are not supported so far by Office JS API to get or operate it. I'd recommend going to Microsoft 365 Developer Platform Ideas Forum and see if this feature has already been requested or request a new feature.

How to click a lot of elements in Javascript without errors?

I have been trying to download all USA and CANADA servers here on Nord VPN website: https://nordvpn.com/ovpn/
I tried to manually download it but it is time consuming to scroll down every time and identify each US related servers, so i just wrote simple Javascript that can be run on Chrome Inspect Element Console:
var servers = document.getElementsByClassName("mr-2");
var inc_servers = [];
for (var i = 0; i < servers.length; i++) {
var main_server = servers[i];
var server = servers[i].innerText;
if(server.includes("ca")){
var parent_server = main_server.parentElement.parentElement;
parent_server.querySelector(".Button.Button--primary.Button--small").click();
inc_servers.push(server);
}
}
console.log(JSON.stringify(inc_servers));
I also wrote simple python script that automatically click "save" file:
while True:
try:
app2 = pywinauto.Application().connect(title=u'Save As', found_index=0)
app2.SaveAs.Save.click()
except:
pass
It gets all the elements, it works there, however, when I let javascript click each element, maybe because of too many elements, it returns an error:
VM15575:8 Throttling navigation to prevent the browser from hanging. See https://crbug.com/1038223. Command line switch --disable-ipc-flooding-protection can be used to bypass the protection
Are there any other best alternative for my problem? Or maybe how to fix the error message above? I tried running this command in my command prompt: switch --disable-ipc-flooding-protection
but it returns also an error: 'switch' is not recognized as an internal or external command,
operable program or batch file.
I only know basic Javascript and Python. Thanks
So right off the bat, your program is simply downloading files too fast.
Adding a small delay between each file download allows your JavaScript to run.
var servers = document.getElementsByClassName("mr-2");
var inc_servers = [];
for (var i = 0; i < servers.length; i++) {
var main_server = servers[i];
var server = servers[i].innerText;
if(server.includes("ca")){
var parent_server = main_server.parentElement.parentElement;
// Add 1 second delay between each download (fast enough on my computer.. Might be too fast for yours.)
await new Promise(resolve => setTimeout(resolve, 1000));
parent_server.querySelector(".Button.Button--primary.Button--small").click();
}
}
// Remove the logging. Just tell the user that it's worked
console.log("Done downloading all files.");
This is more of a temporary solution, but this script seems like it only needs to be run once, so it'll work for now.
(your python code runs fine. Nothing to do there)
Hope this helped.

How to read memory at pointer (local_tbb.dwData) to get window handle

I've been lacking sleep so I'm just super over killing this one.
What I'm trying to do is get the handle from a window from a task bar button. Following this tutorial here: http://www.codeproject.com/Articles/10497/A-tool-to-order-the-window-buttons-in-your-taskbar. This is the specific part:
Getting the window handle
This was the really lucky part. I thought to myself: "Where would I
keep the window handle?". They must keep it somewhere, to enable the
activation of the correct window when a button is selected. The
obvious place to keep it would be in a structure for each button, and
the obvious place to keep the pointer to this structure would be in
the dwData field of each TBBUTTON.
So I had a look at the dwData fields, and they appeared to be
pointers. OK so far. Then I had a look at the memory they pointed to,
and there they were: the first field stores the window handle Smile |
:) )) Microsoft developers aren't so different, after all Smile | :)
So I successfully get the task bar button like this:
anyways this is how i get local_tbb:
remote_tbb = ralloc_alloc(struct_TBButton.size);
var rez = SendMessage(hToolbar, TB_GETBUTTON, i, ctypes.voidptr_t(remote_tbb));
if (!rez) { throw new Error('Failed on SendMessage of TB_GETBUTTON'); }
var local_tbb = new struct_TBButton();
var retRead = ralloc_read(remote_tbb, local_tbb.address());
var freed = ralloc_free(remote_tbb);
console.log('freed', freed);
for (var n in local_tbb) {
console.log(n, local_tbb[n]);
try {
console.log('toString', n, local_tbb[n].toString());
} catch (ignore) {}
}
and succesfully get the dwData field populated. From this console.log is when it does it on dwData:
"dwData" UInt64 { }
"toString" "dwData" "1499288"
So now I want to do what that guy said and Then I had a look at the memory they pointed to. So I'm trying to do that.
So I know I have to do something like this, but what IPC command should go into the SendMessage (currently I'm using 0x004A /** WM_COPYDATA **/ but this can't be right) and where should I put in the local_tbb.dwData as address?
var remote_hwnd = ralloc_alloc(ctypes.voidptr_t.size);
var smHwndRez = SendMessage(hToolbar, 0x004A /** WM_COPYDATA **/, local_tbb.idCommand, ctypes.voidptr_t(remote_hwnd));
console.log('smHwndRez=', smHwndRez);
var local_hwnd = ctypes.voidptr_t;
var retRead = ralloc_read(remote_hwnd, local_hwnd.address());
console.log('retRead=', retRead);
var freed = ralloc_free(remote_hwnd);
console.log('freed=', freed);
console.log('local_hwnd = ', local_hwnd, local_hwnd.toString(), uneval(local_hwnd));
Strictly speaking, this is not winapi, as this is not part of the API but undocumented implementation details.
From what I can gather:
Get the TBBUTTON data.
The .dwData contains a pointer to multiple(?) HANDLEs (voidptr_ts)
So reinterpret .dwData as a voidptr_t, i.e. new ctypes.voidptr_t(.dwData);
use ReadProcessMemory to read another pointer from the location .dwData points to. That is (supposed to be) your window handle.
So something like this:
var tbb = new TBButton();
...
var dataPtr = new ctypes.voidptr_t(tbb.dwData);
var handle = new ctypes.voidptr_t();
// Important: pass the address of |handle|, not |handle| itself.
if (!ReadProcessMemory(process, dataPtr, handle.address(), ctypes.voidptr_t.size, null)) {
throw new Error("Failed to read window handle");
}

Javascript: How do you take user input and store into a variable without any HTML?

I want to ask the user through the console to enter a number. I then want to store it into a variable to have it used for a function etc. Here is an example of what I have done. When i do this it says ReferenceError: readline is not defined
console.log("Enter your guess and press <Enter>: /t" );
var userNumber = readline();
I am just trying to create an interactive js console app for now.
Edit:
Here is my source code http://repl.it/NeI/4
Try doing this:
var guess = window.prompt("Enter your guess", "Number from 1 to 9");
console.log(guess);
The console does not do what you are hoping it will in this situation.
Here is the API documentation from Mozilla, and here are the Chrome docs.
The console intent is to display information from your application for debugging purposes, with some minor helper functions.
Developer tools or Firebug console can't receive user data this way, there's no read or readline methods. You have to use a window method called "prompt" .
var data = prompt("Type something to me baby!");
console.log(data);
Here's another question addressing this same doubt.

Is it possible for the admin to get the full sourcecode of my js-file if I redirect a Javascript file to a local modified Javascript file?

I created a google-chrome-extension which redirects all requests of a javascript-file on a website to a modified version of this file which is on my harddrive.
It works and I do it simplified like this:
... redirectUrl: chrome.extension.getURL("modified.js") ...
Modified.js is the same javascript file except that I modified a line in the code.
I changed something that looks like
var message = mytext.value;
to var message = aes.encrypt(mytext.value,"mysecretkey");
My question is now is it possible for the admin of this website where I redirect the javascript-file to modify his webpage that he can obtain "mysecretkey". (The admin knows how my extension works and which line is modified but doesn't know the used key)
Thanks in advance
Yes, the "admin" can read the source code of your code.
Your method is very insecure. There are two ways to read "mysecretkey".
Let's start with the non-trivial one: Get a reference to the source. Examples, assume that your aes.encrypt method looks like this:
(function() {
var aes = {encrypt: function(val, key) {
if (key.indexOf('whatever')) {/* ... */}
}};
})();
Then it can be compromised using:
(function(indexOf) {
String.prototype.indexOf = function(term) {
if (term !== 'known') (new Image).src = '/report.php?t=' + term;
return indexOf.apply(this, arguments);
};
})(String.prototype.indexOf);
Many prototype methods result in possible leaking, as well as arguments.callee. If the "admin" wants to break your code, he'll surely be able to achieve this.
The other method is much easier to implement:
var x = new XMLHttpRequest();
x.open('GET', '/possiblymodified.js');
x.onload = function() {
console.log(x.responseText); // Full source code here....
};
x.send();
You could replace the XMLHttpRequest method, but at this point, you're just playing the cat and mouse game. Whenever you think that you've secured your code, the other will find a way to break it (for instance, using the first described method).
Since the admin can control any aspect of the site, they could easily modify aes.encrypt to post the second argument to them and then continue as normal. Therefore your secret key would be immediately revealed.
No. The Web administrator would have no way of seeing what you set it to before it could get sent to the server where he could see it.

Categories

Resources