Using Amazon Polly from .net / c#, Get MP3 File

knight-rider-car-kittIf you haven’t checked out Amazon’s new Polly (Text-to-Speech (TTS) cloud service) it does produce some pretty great, life-like audio. Below is a quick sample on how you can feed some text to Polly, and get an MP3 file with it. I don’t cover all of the install options of the AWS Toolkit for Visual Studio / .Net, but it’s pretty simple. (listen to this text here)

Below is some code:

AmazonPollyClient pc = new AmazonPollyClient();

SynthesizeSpeechRequest sreq = new SynthesizeSpeechRequest();
sreq.Text = "Your Sample Text Here";
sreq.OutputFormat = OutputFormat.Mp3;
sreq.VoiceId = VoiceId.Amy;
SynthesizeSpeechResponse sres = pc.SynthesizeSpeech(sreq);

using (var fileStream = File.Create(@"c:\yourfile.mp3"))
{
sres.AudioStream.CopyTo(fileStream);
fileStream.Flush();
fileStream.Close();
}

 

Also make sure you have the below included:

using Amazon.Polly;
using Amazon.Polly.Model;

And these 2 NuGet packages added to your project:

aws-polly

This only scratches the surface of what Polly can do. Between streaming, SSML, Lexicons and more at a great price, I think we’ll be seeing more applications use this.

Using Amazon Polly from .net / c#, Get MP3 File

Cordova or NPM Update Errors – MODULE_NOT_FOUND / EACCES

If you’re taking a break and updating node, npm, cordova or other various packages – you may run into some permission issues causing errors like MODULE_NOT_FOUND or EACCES. Below are some errors I experienced (in OSX 10.11).

These errors were fixed pretty easily by running the below:

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

This command was originally found at:
https://docs.npmjs.com/getting-started/fixing-npm-permissions

npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "update" "-g" "cordova"
npm ERR! node v5.7.0
npm ERR! npm v3.6.0
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'github-url-from-git'

OR:

npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/.staging'

Hope this info helps out someone having the same issues.

Cordova or NPM Update Errors – MODULE_NOT_FOUND / EACCES

Creating a .bash_profile file in OS X and adding PATH directories

If you’re starting out with a fresh install of OS X (10.9 in my example) and are using any development tools, at some point I’m sure you’ll want to add some directories to your system PATH. In short: this allows you to use an application in a specific directory from any other directory – commonly when you’re running commands in Terminal.

To start, we’ll utilize a text editor – in my case I’m using TextMate – but any plain text editor should do. Let’s get to it:

  1. bash_1Let’s first make sure you don’t already have a .bash_profile. In TextMate, go to File > Open. Browse to your home folder (with the house icon) and click “Show Hidden Files”. In your home folder you shouldn’t already see a .bash_profile file. (If you do, then you don’t need to create a new file and can open your file, make changes and skip to step 5.)
  2. bash_2So cancel the open dialog and enter some text into the untitled file currently open. You’re usually entering something like: export PATH=${PATH}:/somedirectory/asubdirectory:/anotherdirectory
  3. bash_3Now let’s save our new .bash_profile. Go to File > Save As. Browse to your home folder (with the little house icon again). Enter the filename as “.bash_profile” (without quotes).
  4. bash_4If you get a message saying “names that begin with a dot are reserved for the system” chose “Use ‘.’
  5. bash_5That’s it. Now if you already have a terminal open run source ~/.bash_profile (this just give you access to the updated PATH).
Creating a .bash_profile file in OS X and adding PATH directories

Upgrading Apache Cordova to latest version

Updating Apache Cordova to the latest version only takes a few minutes. Below are the steps (taken from Cordova) needed to update your > 3.0 projects to the latest version (3.5 as of this post).

In a command / terminal run:

  1. npm install -g cordova
  2. Now go to into your project (ie: c:\projects\test)  and run:
  3. cordova platform update android (or ios)

 

You can update your plugins by removing / adding them again like:

cordova plugin rm org.apache.cordova.file
cordova plugin add org.apache.cordova.file

That’s it. Now you should have an up to date environment.

Upgrading Apache Cordova to latest version

New App Version IOS / iTunes Connect CFBundleVersion Error

App_Store_Logo

When adding a new version of your app to iTunes Connect, you may run across the below error:

ERROR ITMS-9000: “This bundle is invalid. The value for key CFBundleVersion [1.0] in the Info.plist file must contain a higher version than that of the previously uploaded version [1.0].” at SoftwareAssets/SoftwareAsset (MZItmspSoftwareAssetPackage)

This version (CFBundleVersion) is the build version of your bundle and can be different (more frequent) than your release version number (aka CFBundleShortVersionString).

You can edit this version in the info.plist file

bundleversion

From Apple:

The build version number should be a string comprised of three non-negative, period-separated integers with the first integer being greater than zero. The string should only contain numeric (0-9) and period (.) characters. Leading zeros are truncated from each integer and will be ignored (that is, 1.02.3 is equivalent to 1.2.3).

After updating your info.plist you should be able to rebuild and upload your new / updated version without issue. -Now you just need to wait for Apple to approve…

New App Version IOS / iTunes Connect CFBundleVersion Error

Renaming a local file in Cordova / PhoneGap

A few folks have asked “how do I simply rename a local file in Cordova?” Well, to start, you’ll need the file plugin from Apache Cordova. If you don’t already have this, run the below to add the file plugin.

cordova plugin add org.apache.cordova.core.file

Then, you can use the “moveTo” function to rename the file. Below is a reusable function I utilize to pass the current file name, directory, the new file name and a function that happens when the rename is successful.

You can utilize the below function like:

//to call the function. 'renameSuccess' is an function that is used as the success event if the rename is okay
renameFile('somefile.xml','myapp/xml/','new.xml', renameSuccess);

//the function
function renameFile(currentName, currentDir, newName, successFunction) {

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {

        fileSystem.root.getFile(currentDir + currentName, null, function (fileEntry) {
            fileSystem.root.getDirectory(currentDir, {create: true}, function (dirEntry) {
                parentEntry = new DirectoryEntry(currentName, currentDir + currentName);

                fileEntry.moveTo(dirEntry, newName, function () {

                    successFunction();

                }, renameFail);
            }, renameFail);
        }, renameFail);

    }, renameFail);
}

//and the sample success function
function renameSuccess() {
    alert('renamed!');
}

//and the sample fail function
function renameFail() {
    alert('failed');
}

I’m not saying this is the ‘best’ way to do this, so feel free to comment on improvements!

Renaming a local file in Cordova / PhoneGap

Allow Local File Access in Chrome (Windows)

chrome-128Sometimes it’s cool to debug and test javascript applications in Chrome but you want to read / write to local files. Example: you’re looking to use ajax and do a $.getJSON(‘json/somefile.json’). Chrome by default won’t allow this and will throw an error similar to:

Failed to load resource: No 'Access-Control-Allow-Origin' 
header is present on the requested resource. 
Origin 'null' is therefore not allowed access.

Or
XMLHttpRequest cannot load. No 'Access-Control-Allow-Origin' 
header is present on the requested resource. 
Origin 'null' is therefore not allowed access.

Chrome does have a switch to enable this, it’s quite easy to turn on. You’ll need to make sure Chrome is closed completely, and run chrome with the ‘–allow-file-access-from-files’ flag. Ie:

C:\Users\<user>\AppData\Local\Google\Chrome\Application>
chrome --allow-file-access-from-files

Or you should be able to run:

%localappdata%\google\chrome\application\chrome --allow-file-access-from-files

I’ve made the below into a .bat file I use, if you find it helps.

start "chrome" %localappdata%\google\chrome\application\chrome --allow-file-access-from-files
exit

To see if the flag is set, you can visit:  chrome://version/ and look at the Command Line section and you should see –allow-file-access-from-files

You’ll most likely need to run this with at least admin access, and I would caution visiting unknown sites with this setting on, as they could capitalize on your setting and potentially read local files.

Update, see my newer post on using node and http-server to create a local web server to get around these issues:
Local web server for testing / development using Node.js and http-server

Allow Local File Access in Chrome (Windows)

Installing & starting with PhoneGap on Windows for cross platform mobile development

Build-BotPhoneGap is a great framework for creating cross platform apps (Android, iOS, BB, WM, etc.) using HTML, CSS, and JavaScript and uses Apache Cordova™. Installing and testing on Windows takes little setup, below I’ve tried to cover all of the steps needed to get going. My setup / guide below uses Windows 7, 64 bit, it seems like many steps, but in reality is pretty easy.

  1. Install node.js from nodejs.org (use default settings).
  2. Open a command prompt (cmd) and run:
    1. npm install -g phonegap
    2. npm install -g ant
    3. npm install –g cordova
    4. Now add ‘C:\Users\<yourusername>\AppData\Roaming\npm\node_modules\ant\ant\bin’ to the Path system variable
    5. Download and extract the Android SDK from https://developer.android.com/sdk/index.html
      1. I extracted to c:\mobile\androidsdk (referenced below as <yoursdkpath>)
      2. Add <yoursdkpath> + \sdk\platform-tools to the Path system variable
      3. Add <yoursdkpath> + \sdk\tools to the Path system variable
      4. Now to setup an Android image to emulate and test with:
        1. In the sdk folder, run Eclipse (ie: C:\mobile\androidsdk\eclipse\eclipse.exe
        2. Create or use the default workspace
        3. In Eclipse, under Window choose Android SDK Manager
        4. In the SDK Manager, make sure these are checked:
        5. i.      Tools > SDK Tools, Platform-tools
        6. ii.      Android <you choose the version> SDK Platform, Arm system image & Intel system image (if available)
        7. iii.      Extras > Android Support Library, Google USB Driver, Intel x86 emulator HAXM
  3. Click Install x Packages, accept all licenses
  4. When downloads are finished, close the SDK Manager
  5. If you want to speed up the Android emulator, I suggest installing the Intel HAXM located at: \sdk\extras\intel\Hardware_Accelerated_Execution_Manager
  6. Now back in Eclipse (restart if you’ve installed the HAXM), you can go to Window > Android Virtual Device Manager.
  7. Click “New” to create a new virtual device
  8. Choose a name (anything you want)
  9. Choose a device (something simple like the “4.0” WVGA”)
  10. Choose a target (this is what you downloaded in step 4d).
  11. In CPU, choose Intel if it’s available (it’s not required, but if it’s not available, double check the HAXM install and the download the Intel system image for your target version)
  12. Now you can click “OK”
  13. In the list of virtual devices, choose your new device and click “Start”
  14. Provided you don’t see any errors, after a few minutes (be patient) you’ll have a working Android emulator going. android-emulator
  15. Now, let’s do a quick project and test it! Go back to cmd (your command prompt).
  16. Create your project with, run: cordova create hello com.ex.hello “HelloChris”
  17. Go to the project directory, run: cd hello
  18. Add android to the project, run: cordova platform add android
  19. To make sure your project is ok, run: cordova build
  20. Now if you don’t already have your emulator running, go back into Eclipse into the Android Virtual Device Manager and start your device.
  21. When it’s running, run: cordova emulate android
  22. That’s it; you should see “your” app on the emulator in a few seconds. (It reads “device ready” with a logo or something…).

Continue reading “Installing & starting with PhoneGap on Windows for cross platform mobile development”

Installing & starting with PhoneGap on Windows for cross platform mobile development

Titanium Studio / SDK – Deploying To Android Device Issue

Titanium SDK is a great tool for developing cross platform mobile apps. But if you’ve got a Samsung Galaxy (S3 or S4) and noticed that with the new updates, even with USB Dev Debug on, Titanium still can’t deploy to your device, chances are you just need to install the Samsung ADB driver. Below is the official link. [Beware of non-Samsung links on the web.]

http://developer.samsung.com/android/tools-sdks/Samsung-Andorid-USB-Driver-for-Windows

 

Titanium Studio / SDK – Deploying To Android Device Issue

Corona Cider – Corona IDE

Just a heads up, if you’re running 64 bit Windows and only have the 64 bit java sdk installed, you’ll get an error when running the IDE. To cure, download the 32 bit version of the java sdk (1.6) and install. Seems good now!

Java download:

http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u32-downloads-1594644.html

Corona Cider IDE:

http://www.mydevelopersgames.com/CIDER/

 

More Cider info to follow shortly!

Corona Cider – Corona IDE