Click here to Skip to main content
Click here to Skip to main content

Generate flash agents with voice in asp.net

, 8 May 2006
Rate this:
Please Sign up or sign in to vote.
Generate your Macromedia flash agents with tts voice in asp.net.

Sample Image - TTS.jpg

Introduction

Have you visited http://www.oddcast.com/ ? With this library you can create your agents in flash with lipsync and dinamically generated (sapi tts) audio in every language.

You need some know-how in javascript, actionscript (very similar to javascript) and Macromedia flash.

You need to istall in your test server:

  1. latest Microsoft Speech SDK installed on your test server (with the Microsoft English Recognizer set as default ASR);
  2. MingX, an free activex to generate Macromedia swf files;
  3. A free utility from James Anderson to extract the phonemes from a wave file;
  4. Lame.exe, a free utility to generate mp3 files on the fly;
  5. Some good SAPI 5.1 compliant voice to have good result (try Cepstral voices);

The process to use the library is very simple:

  1. a page (asp.net very simple) receive as POST DATA the text to TTS, the voice to use, and the swf filename to generate (without extension);
  2. calling (in this order: Genera.Wave, Genera.Mp3, Genera.Asr, Genera.FlashSwf) the functions of the library (and passing the appropriate data), will generate a swf file with embedded the TTS audio in mp3 format, and for each Flash frame the appropriate mouth position (based on the classical 13 disney visemes) for the lipsync.

A brief description of the functions (remember use Filename without extension):

  • Genera.wave(Text, Filename, Voice) used to generate a wave from from a SAPI 5.1 compatible voice;
  • Genera.Mp3(Filename) used to generate an mp3 file to use with Macromedia swf;
  • Genera.Asr(FileName) used to generate with the James Anderson utility a text files with the timing an the phonemes to use later for the lipsync;
  • Genera.FlashSwf(FileName) used to generate the swf file with the embedded audio and the mouth position for every flash frame;
  • LeggiVociInstallate() used to get a list of the installed voice on the server.

Every functions return "OK" is the process is finished without error or return an error. 

To test in win 2003 the used ApplicationPool in IIS MUST BE SET to LocalSystem (to work with SAPI).

I have tested the library with italian voice, german voice and english voice and is work well (for the lipsync).

Here an example of an asp.net page to post the data:

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<A href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</A>">

 

Here an example of the page that receive the post data (tts.aspx) and the code inside:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Tts.aspx.vb" Inherits="Tts" %>
 
Imports TtsSwf<BR>Partial Class Tts<BR>    Inherits System.Web.UI.Page
    Public GenerateError As Boolean = False
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<BR>        Dim Genera As TtsSwf.Genera = New TtsSwf.Genera()<BR>        'Dim Testo As String = Request.QueryString("Text")<BR>        'Dim FileName As String = Request.QueryString("FileName")<BR>        'Dim Voce As String = Request.QueryString("Voce")
        Dim Testo As String = Request.Form("Testo")<BR>        Dim FileName As String = Request.Form("FileName")<BR>        Dim Voce As String = Request.Form("Voce")
        If Testo <> "" And FileName <> "" And Voce <> "" Then
            If Genera.Wave(Testo, FileName, Voce) <> "OK" Then<BR>                SetError()<BR>            End If
            If GenerateError = False Then<BR>                If Genera.Mp3(FileName) <> "OK" Then<BR>                    SetError()<BR>                End If<BR>            End If
            If GenerateError = False Then<BR>                If Genera.Asr(FileName) <> "OK" Then<BR>                    SetError()<BR>                End If<BR>            End If
            If GenerateError = False Then<BR>                If Genera.FlashSwf(FileName) <> "OK" Then<BR>                    SetError()<BR>                End If<BR>            End If
            Genera.Fine(FileName)
        End If<BR>        Response.Write("Testo:" + Testo + " voce:" + Voce + " filename:" + FileName)
    End Sub
 
    Sub SetError()<BR>        GenerateError = True<BR>    End Sub<BR>End Class

You can also use a main flash (with the mouth positions) swf to call the page to generate the swf and to load the generated swf.

A brief example:

Create an swf movie putting in a frame this action script code:

<BR>sendinfo = new LoadVars ();<BR><BR>sendinfo.Testo = testo;<BR><BR>sendinfo.FileName = filename;<BR><BR>sendinfo.Voce = voce;<BR><BR>sendinfo.sendAndLoad("http://otherserver/tts.aspx", _root, "POST");<BR><BR>loadMovie (("http://otherserver/ttscache/" + filename) + ".swf", "_root.codice");<BR><BR>delete testo;<BR><BR>delete filename;<BR><BR>delete voce;<BR><BR>par = _root.codice.getBytesLoaded();<BR><BR>tot = _root.codice.getBytesTotal();<BR><BR>if (par == tot) {<BR><BR>caricamento = "Ok";<BR><BR>}<BR>

Label this frame as "sayText".

Create a simple html page where put this javascript code and where you load the main movie:

<BR><script language="javascript"><BR>function sayText(Text,FileName,Voice)<BR>{<BR>    var movie = window.document.test<BR><BR>    movie.SetVariable("testo",Testo);<BR>    movie.SetVariable("filename",FileName);<BR>    movie.SetVariable("voce",Voce);<BR>    movie.TCallLabel("/", "sayText");<BR>}<BR><BR>function Prova(){<BR> sayText('spero di aver finito il test.','2','5');<BR>}<BR></script><BR>

Create a link (like this) in the page: <a href="javascript:Prova();">Prova testo.<a>

The link call the actionscript (label sayText) in the main flash movie.

The flash call the page posting the data.

The page create the swf file with the audio and the mouth positions.

Once is loaded the main movie start the generated file.

Warning: if you put the main movie in a domain (ex: www.cisco.com) and the loaded movie is generated on an other server (www.microsoft.com) for security reasons this don't work.

Put this file in the generation server (naming it crossdomain.xml):

<?xml version="1.0"?><BR><!DOCTYPE cross-domain-policy <BR>SYSTEM "<A href="http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd</A>"><BR><cross-domain-policy><BR><allow-access-from domain="*" /><BR></cross-domain-policy>

To do:

  1. Use the Annosoft SAPI lipsync to generate the phonemes and the timings;
  2. Improve the generation of the swf files;

I think this library can be useful to every webmaster.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Claudio Pizzillo
Software Developer (Senior) KefaOnLine di Techworld S.r.l.
Italy Italy
VB.NET, C# Developer.
Skills: VB.Net, ASP.Net, SQL 2000/2005.

Comments and Discussions

 
Generalheeeeelp! Pinmembermiganok31-Aug-08 0:17 
Generalfla Pinmembermiganok30-Aug-08 5:09 
GeneralHi,can you help me PinmemberMember 43773591-Apr-08 22:19 
GeneralAnnosoft sapi_lipsync.exe Pinmemberdrfunky1-May-07 17:16 
QuestionSynchronization in wave phonems with Frames in SWF file PinmemberHimal Rupera14-Dec-06 1:05 
AnswerRe: Synchronization in wave phonems with Frames in SWF file PinmemberClaudio Pizzillo14-Dec-06 1:38 
QuestionRe: Synchronization in wave phonems with Frames in SWF file PinmemberHimal Rupera14-Dec-06 3:27 
GeneralI got mine working! Here's how! [modified] Pinmembermikmoth25-Oct-06 15:37 
QuestionHow can i get the flash model file to test PinmemberVu Anh Viet23-Aug-06 0:05 
AnswerRe: How can i get the flash model file to test PinmemberClaudio Pizzillo23-Sep-06 23:53 
GeneralNew test OK PinmemberClaudio Pizzillo30-May-06 6:14 
GeneralProblem Pinmemberrob_houweling29-May-06 23:34 
Hey,
 
Nice article, but the attached zip doesn't contain the sources and when I try to use the DLL's in my VS2003 or VS2005 it gives an error that it isn't a valid COM or .NET dll.
 
Really could use some help....
 
Kind regards,
 
Rob.
GeneralRe: Problem PinmemberClaudio Pizzillo30-May-06 6:08 
Generalexcellent :) PinmemberIftahh8-May-06 11:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411023.1 | Last Updated 8 May 2006
Article Copyright 2006 by Claudio Pizzillo
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid