I'm currently working on an application that is a language translator. I already know that Flash professional or both Flash is very picky of audio files. Like when you're trying to import an audio to your FLA's library, you get this error saying: Couldn't import '.mp3' I think the same thing happens with my Sound controller class, when I try to load a text to speech from an api server from some translator api that I'm not gonna show. Translate class:
class nodes.Translate
{
var fromType;
var toType;
var query;
var loader;
var response;
var targetFrom;
var targetTo;
static var instance;
static var API_KEY = "5kMZ4F5UfRt4";
static var TRANSLATE_TEMPLATE = "http://<domain/ip>/api/translate";
static var TEXT_TO_SPEECH_TEMPLATE = "http://<domain/ip>/translate_tts";
function _translate(pFrom, pTo, pQuery)
{
this.fromType = pFrom;
this.toType = pTo;
this.query = pQuery;
this.loadAndParse();
}
static function getInstance()
{
if (nodes.Translate.instance == null || nodes.Translate.instance == undefined)
{
nodes.Translate.instance = new nodes.Translate();
}
return nodes.Translate.instance;
}
function loadAndParse()
{
this.loader = new LoadVars();
this.loader.onLoad = function(success)
{
if (success)
{
try
{
var decodedResponse:String = unescape(this.toString());
this.response = sugar.utils.JSONDecoder.deserialize(decodedResponse);
var translation = this.response.to;
var original = this.response.from;
_global.Translator.getInstance().outputContainer.field.text = translation;
_global.Translator.getInstance().outputContainer.field.setTextFormat(_global.Translator.getInstance().outputFormat);
nodes.Translate.getInstance().playTTS(translation);
}
catch (e)
{
trace("Error parsing JSON: " + e.message);
}
}
else
{
trace("Error loading translation.");
}
};
trace(("Request URL: " + this.makeUrl()));
this.loader.load(this.makeUrl());
}
function playTTS(text)
{
var ttsUrl = this.makeTTSUrl(text);
var soundController = sounds.SoundController.getInstance();
soundController.playSound(ttsUrl,true);
}
function makeTTSUrl(text)
{
return nodes.Translate.TEXT_TO_SPEECH_TEMPLATE + "?ie=UTF-8&client=gtx&q=" + this.encodeURIComponent(text) + "&tl=" + this.toType + "&total=1&idx=0&textlen=" + text.length;
}
function encodeURIComponent(str)
{
var encodedStr:String = "";
for (var i = 0; i < str.length; i++)
{
var charCode = str.charCodeAt(i);
if ((charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) || (charCode >= 48 && charCode <= 57) || (charCode == 45 || charCode == 46 || charCode == 95 || charCode == 126))
{
encodedStr += str.charAt(i);
}
else
{
encodedStr += "%" + charCode.toString(16).toUpperCase();
}
}
return encodedStr;
}
class sounds.SoundController
{
var _sound;
static var instance;
function SoundController()
{
super();
}
static function getInstance()
{
if (sounds.SoundController.instance == null || sounds.SoundController.instance == undefined)
{
sounds.SoundController.instance = new sounds.SoundController();
}
return sounds.SoundController.instance;
}
function playSound(pSoundUrl:String, pValue:Boolean)
{
this._sound = new Sound();
this._sound.loadSound(pSoundUrl, pValue);
this._sound.onLoad = function(success)
{
if (success)
{
sounds.SoundController.getInstance()._sound.start();
}
else
{
trace("Error loading sound.");
}
};
}
}
The question is that, is there any fixing of that mp3 not loading or playing from the server, so I won't have to call FFMPEG to convert the tts audio from the translator API to the correct audio codec for Flash?