Click here to Skip to main content
15,389,125 members
Articles / Web Development / ASP.NET
Article
Posted 8 May 2006

Stats

61.7K views
955 downloads
46 bookmarked

Generate flash agents with voice in asp.net

Rate me:
Please Sign up or sign in to vote.
4.14/5 (7 votes)
8 May 20063 min read
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:

ASP.NET
<%@ 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>">
<html xmlns="<A href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</A>" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <div>
    <form method="post" action="<A href="http://otherserver/tts.aspx">http://otherserver/tts.aspx</A>">
    <input type="text" name="Testo" value="prova testo" /><br />
    <input type="text" name="Voce" value="5" /><br />
    <input type="text" name="FileName" value="3" /><br />
    <input type="submit" value="Vai"/>
    </form>    </div>
</body>
</html>

 

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

ASP.NET
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Tts.aspx.vb" Inherits="Tts" %>
ASP.NET

ASP.NET
Imports TtsSwf<BR>Partial Class Tts<BR>    Inherits System.Web.UI.Page
ASP.NET
Public GenerateError As Boolean = False
ASP.NET
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")
ASP.NET
Dim Testo As String = Request.Form("Testo")<BR>        Dim FileName As String = Request.Form("FileName")<BR>        Dim Voce As String = Request.Form("Voce")
ASP.NET
If Testo <> "" And FileName <> "" And Voce <> "" Then
ASP.NET
If Genera.Wave(Testo, FileName, Voce) <> "OK" Then<BR>                SetError()<BR>            End If
ASP.NET
If GenerateError = False Then<BR>                If Genera.Mp3(FileName) <> "OK" Then<BR>                    SetError()<BR>                End If<BR>            End If
ASP.NET
If GenerateError = False Then<BR>                If Genera.Asr(FileName) <> "OK" Then<BR>                    SetError()<BR>                End If<BR>            End If
ASP.NET
If GenerateError = False Then<BR>                If Genera.FlashSwf(FileName) <> "OK" Then<BR>                    SetError()<BR>                End If<BR>            End If
ASP.NET
Genera.Fine(FileName)
ASP.NET
End If<BR>        Response.Write("Testo:" + Testo + " voce:" + Voce + " filename:" + FileName)
ASP.NET
End Sub
ASP.NET

ASP.NET
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! Pin
miganok30-Aug-08 23:17
Membermiganok30-Aug-08 23:17 
Generalfla Pin
miganok30-Aug-08 4:09
Membermiganok30-Aug-08 4:09 
GeneralHi,can you help me Pin
Member 43773591-Apr-08 21:19
MemberMember 43773591-Apr-08 21:19 
GeneralAnnosoft sapi_lipsync.exe Pin
drfunky1-May-07 16:16
Memberdrfunky1-May-07 16:16 
Annosoft's sapi_lipsync.exe is a way better tool for lipsync. Has anyone replaced the phonemes.exe with Annosoft's sapi_lipsync.exe? If so please show an example.

Big Grin | :-D
QuestionSynchronization in wave phonems with Frames in SWF file Pin
Tejal Bhavsar14-Dec-06 0:05
MemberTejal Bhavsar14-Dec-06 0:05 
AnswerRe: Synchronization in wave phonems with Frames in SWF file Pin
Claudio Pizzillo14-Dec-06 0:38
MemberClaudio Pizzillo14-Dec-06 0:38 
QuestionRe: Synchronization in wave phonems with Frames in SWF file Pin
Tejal Bhavsar14-Dec-06 2:27
MemberTejal Bhavsar14-Dec-06 2:27 
GeneralI got mine working! Here's how! [modified] Pin
mikmoth25-Oct-06 14:37
Membermikmoth25-Oct-06 14:37 
QuestionHow can i get the flash model file to test Pin
Vu Anh Viet22-Aug-06 23:05
MemberVu Anh Viet22-Aug-06 23:05 
AnswerRe: How can i get the flash model file to test Pin
Claudio Pizzillo23-Sep-06 22:53
MemberClaudio Pizzillo23-Sep-06 22:53 
GeneralNew test OK Pin
Claudio Pizzillo30-May-06 5:14
MemberClaudio Pizzillo30-May-06 5:14 
GeneralProblem Pin
rob_houweling29-May-06 22:34
Memberrob_houweling29-May-06 22:34 
GeneralRe: Problem Pin
Claudio Pizzillo30-May-06 5:08
MemberClaudio Pizzillo30-May-06 5:08 
Generalexcellent :) Pin
Iftahh8-May-06 10:45
MemberIftahh8-May-06 10:45 

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

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