What is the best way to send String input to Google Text-to-Speech? - formatting

I have a few paragraphs that needs to be put through the Google TTS API for conversion. Some of these sentences have Dynamic words in them (eg: username). By simply passing the entire text to the API, it's taking around 8-9 secs for the Google API to respond (since some of these sentences are significantly larger in size)
What is the best strategy for converting these sentences?
I was hoping I could first convert the Static part of the sentences and store it somewhere and then convert the Dynamic part, and somehow insert the byte response of the Dynamic word. But I am not sure if this can be done at all.
For eg:
Hi, User how are you?
I was hoping to store the byte responses for "Hi," and then "how are you?" and then insert the byte response for "User" in the appropriate position

Related

PHP: Google Translate 5000 characters limit

I'm using this library for translating:
https://github.com/dejurin/php-google-translate-for-free
It's possible to translate more than 5000 characters with this library?
Or save the translated text to a txt and change from text translate to docs translate?
I mean this:
https://translate.google.com/#view=home&op=docs&sl=en&tl=lb
Based on what Google says, it is not possible to send more than 5,000 characters per request. Moreover, Google recommends that you send less than 5,000.
You can find it here under technical questions : Google Translate FAQ
Regarding the second question, ii is possible.
According to the website of the library the result of the translation is returned in the form of an array, so first of all you must do is convert the array into a string, separating each element of the array by what you decide (here I separate it by a blank space):
$arrayToString = implode(' ', $result);
Here $result is the array returned by the library. Now we just have to save the string in a txt file.
$file = 'path/to/file/filename.txt';
file_put_contents($file, $arrayToString);
Regards

google authenticator vs vbscript

I have implemented this http://jacob.jkrall.net/totp/ in vbscript.
My code given the same hex gives the right 6-digit otp, so that part is working.
I've also verified the HMAC-SHA-1. encoding against an online generator, http://www.freeformatter.com/hmac-generator.html#ad-output, same input gives same output.
My time is the same as http://www.currenttimestamp.com/
I've generated a qrcode at http://www.qr-koder.dk/ with the string otpauth://totp/$LABEL?secret=$SECRET and the google authenticator app reads the code and starts outputting the 6 digit code changing every 30 seconds.
BUT THE CODES FROM THE APP DOES NOT MATCH THE 6-DIGIT CODE THE VBSCRIPT GENERATES!
I've even tried trunc(time/30) +/-7500 steps to see if it was a timezone/daylight saving problem, to no avail.
As the other parts of the routine to generate the 6 digits seem to work I've come to the conclusion I don't understand this:
the url on the qr-code is
otpauth://totp/$LABEL?secret=$SECRET
with the explanation
LABEL can be used to describe the key in your app, while SECRET is the
16-character base32-encoded shared secret, which is now known to both
the client and the server.
So when I calculate HMAC-SHA-1(SECRET, time()/30)
should the SECRET be the same string given to both the app and the calculation?
If I select a secret of 1234567890, the base32 is GEZDGNBVGY3TQOJQ according to http://emn178.github.io/online-tools/base32_encode.html.
Should I then take
HMAC-SHA-1("1234567890", time()/30)
or
HMAC-SHA-1("GEZDGNBVGY3TQOJQ", time()/30)
?
I believe I've tried both, and neither works.
The system unix time is correct.
I guess the problem might be with the secret in your HMAC-SHA-1 function. It very much depends on what the HMAC-SHA-1 expects.
Your string "123456790" might be a binary string. Is it an ascii representation or utf8? I.e. is this string 10 bytes or 20 bytes long?
I recommend getting the input string in your VBScript right.
On the other hand, instead of writing your own VBScript, you can also use a ready made solution like the privacyIDEA authentication server, which is open source and also comes with TOTP.

Possible to write an Express GET route that accepts an array of unknown length?

Like the title says, is it possible to write an Express GET route that accepts an array of unknown length?
I know I can use a POST request and just include an array in the body, but it isn't posting something so much as getting something!
I need to know how to encode the url. Most of what I am seeing is for arrays of particular length. This could be for 2 or 20, or more.
YES!
You can use the query parameter and use a delimiter, as search engines of old where your search string was actually in the url with spaces demarcated with +. This allows for an array of indeterminate length.
Did not get any feedback for HOW to encode an array to accept a url, so this is the approach I am going with. Even in my googling I couldn't find much on HOW to encode a URL to have an array in the params object, rather than the query object, possibly because I was searching for how to do it for an array of indeterminate length?

Error 414 -The requested URL is too large to process

I am using Google Chart API in my Application and generating graph using URL "http://chart.apis.google.com"
I am getting error "The requested URL is too large to process", when I provide large set of parameters to this URL.
What I can do in this situation?
The Google Charts API FAQ offers this advice:
Is there a limit on the URL length for the Google Chart API? What is the maximum URL length?
The maximum length of a URL is not determined by the Google Chart API, but rather by web browser and web server considerations. The longest URL that Google accepts in a chart GET request is 2048 characters in length, after URL-encoding (e.g., | becomes %7C). For POST, this limit is 16K.
If URL length is a problem, here are a few suggestions for shortening your URL:
If you are using a text encoding data format, remove leading zeros from numbers, remove trailing zeros after decimal points, and round or truncate the numbers after decimal points.
If that does not shorten the URL enough, use simple (1 character) or extended (2 character) encoding.
Sample data less frequently; i.e., reduce granularity.
Remove accoutrements and decorations, such as colors, labels, and styles, from your chart.
also found this but there doesn't seem to be an answer/solution.
http://groups.google.com/group/google-chart-api/browse_thread/thread/b47c1588b39d98ce
In case it is a browser error - browsers have their maximum URL length limitations (IE 6/7 has 2,083 limit):
What is the maximum length of a URL in different browsers?
I'm getting HTTP 414 but my URL length is not an issue (it is 1881 characters), and I have tried both GET and POST. My guess is that Google will also return this error when the chart you are requesting is too "expensive" to generate.
A method that worked well for me was to divide all values by 10 or 20 and converting the results to int (no commas), but I kept the numbers on the axis. This way, it's a little less accurate but reduces the amount of characters used in the URL.
Code example:
$newSalesrank = $rank/20;
$rankdata .= intval($newSalesrank);
This solved my problem, I got no more "url too long" errors and it still looks good on my charts - because it still looked the same, the numbers just were simply scaled down.

How Do I Convert a Byte Stream to a Text String?

I'm working on a licensing system for my application. I'd like to put all licensing information (licensee name, expiration date, and enabled features) into an object, encrypt that object with a private key, then represent the encrypted data as a single text string which I can send via email to my customers.
I've managed to get the encrypted data into a byte stream, but I don't know how to convert that byte stream into a text value -- something that contains no control characters or whitespace. Can anyone offer advice on how to do that? I've been researching the Encoding class, but I can't find a text-only encoding.
I'm using Net 2.0 -- mostly VB, but I can do C# also.
Use a Base64Encoder to convert it to a text string that can be decoded with a Base64Decoder. It is great for representing arbitary binary data in a text friendly manner, only upper and lower case A-Z and 0-9 digits.
BinHex is an example of one way to do that. It may not be exactly what you want -- for example, you might want to encode your data such that it's impossible to inadvertently spell words in your string, and you may or may not care about maximizing the density of information. But it's an example that may help you come up with your own encoding.
I've found Base32 useful for license keys before. There are some C# implementations linked from this answer. My own license code is based on this implementation, which avoids ambiguous characters to make it easier to retype the keys.