TTS speech with actors and dialogues

Author Message
AMBience

  • Total Posts : 31
  • Scores: 0
  • Reward points : 0
  • Joined: 7/24/2008
  • Status: offline
TTS speech with actors and dialogues Friday, February 11, 2011 11:54 AM (permalink)
0
This HTA app will let you define "actors" for TTS speech and have them hold conversations with each other.

I first wrote this with lots of select boxes, text boxes and buttons....but it was a pain to actually edit the script (like simply inserting a line of dialogue before another), so I thought why not just have a large text area with everything in text and parse it?  This is great because it's easy for me to code and you to edit as well as not needing any save\load mechanisms, just copy and paste.

Includes speech monitoring, transcript pausing and quick audition...all the info you need to use it is in the default demo.

<HTML><HEAD>
 <TITLE>Convo - By Alan Bond</TITLE>
 <HTA:APPLICATION
 SINGLEINSTANCE = "yes"
 MAXIMIZEBUTTON = "no"
 MINIMIZEBUTTON = "no"
 BORDER = "thin"
 />
</HEAD>
<BODY SCROLL="No" STYLE="Border:0;Margin:0" BGCOLOR="ButtonFace">
<INPUT TYPE="button" ID="cmdPlay" VALUE="Play" STYLE="Height:4%;"/>
<INPUT TYPE="button" ID="cmdPaste" VALUE="Paste" STYLE="Height:4%;"/>

<!-- '---- Default convo & instructions ----' -->
<TEXTAREA ID="txtScript" STYLE="Width:100%;Height:96%;">
'-------- Actors --------
'$Actor name
'Voice = (0=Sam, 1=Mike, 2=Mary) You need the SpeechSDK for Mike & Mary (this demo just uses Sam)
'Pitch = -25 to 25 (Giant\human\Pixy)
'Speed = -25 to 25 (below -10 is really slow!)
'Volume 0-100
'------------------------

$SamFastQuiet
Voice = 0
Pitch = 25
Speed = 1
Volume = 30

$SamFastLoud
Voice = 0
Pitch = 25
Speed = 1
Volume = 100

$SamSlow
Voice = 0
Pitch = -15
Speed = -4
Volume = 100

'-------- Script --------
'Format:- Actor name : Text
'Fast audition:- Place a single asterisk above any line to start the conversation at that point.
'Pause:- Use %Number between lines to add a pause (milliseconds)
'------------------------

SamFastQuiet: hello there!
SamSlow : I cant hear you, come over here
%1500
SamFastLoud : I said, hello there?
SamSlow : hi!
</TEXTAREA>
</BODY>

<SCRIPT LANGUAGE="VBScript">

Option Explicit

Dim intMaxLine, intCurLine, blnPlaying, blnPaused

'---- A dictionary for storing voice values ----'
Dim dctActors : Set dctActors = CreateObject("Scripting.Dictionary")

'---- A dictionary for storing script lines ----'
Dim dctScript : Set dctScript = CreateObject("Scripting.Dictionary")

'---- Start the speech watcher interval ----'
Dim intPlayInterval : intPlayInterval = window.setInterval ("Playing", 1)

'---- Setup SPVoice ----'
Dim TTS:Set TTS = CreateObject("Sapi.SpVoice")
blnPlaying=False : blnPaused=False

'---- Paste button click (clears all previous text to be safe) ----'
Sub cmdPaste_OnClick()
 txtScript.InnerText = Window.ClipboardData.GetData("Text")
End Sub

'---- Play\Stop button click ----'
Sub cmdPlay_OnClick()
 
 '---- Parse & play
 If Me.Value = "Play" Then
 Parse
 blnPlaying = True
 cmdPlay.Value = "Stop"

 '---- Stop script. You can't force a stop, so jump to the last script line ----'
 Else
 intCurLine=intMaxLine
 Me.Value = "Stopping.....Please wait"
 End If
End Sub

'---- Parse text ----'
Sub Parse()
 Dim L, strLine, strLineSplit, strWordSplit, strCurActor

 '---- Reset dictionaries ----'
 dctActors.RemoveAll : dctScript.RemoveAll
 intMaxLine = 0 : intCurLine=-1

 '---- Split textarea text with VBCRLF ----'
 strLineSplit = Split(txtScript.InnerText,VBCRLF)

 For L = 0 To UBound(strLineSplit)

 '---- Tidy line ----'
 strLine=LCase(Trim(Replace(strLineSplit(L),VBTab,"")))  ' you can't tab, but you could paste text with tabs in it

 '---- Ignore empty lines and comments ----'
 If strLine<>"" And Left(strLine,1)<>"'" Then

 '---- [$] Actor definition ----'
 If Left(strLine,1)="$" Then
 strCurActor = Right(strLine,Len(strLine)-1)

 '---- [=] Actor properties ----'
 ElseIf Instr(strLine,"=") Then
 strWordSplit = Split(strLine,"=")
 dctActors.Item(strCurActor & "." & Trim(strWordSplit(0)))=Trim(strWordSplit(1))

 '---- [:] Actor transcript ----'
 ElseIf Instr(strLine,":") Then
 strWordSplit = Split(strLine,":")
 dctScript.Item(intMaxLine) = Trim(strWordSplit(0)) & "\" & Trim(strWordSplit(1))
 intMaxLine = intMaxLine + 1

 '---- [%] A pause ----'
 ElseIf Left(strLine,1)="%" Then
 strLine = Right(strLine,Len(strLine)-1)
 dctScript.Item(intMaxLine) = "%PAWS%\" & Trim(strLine)
 intMaxLine = intMaxLine + 1

 '---- [*] Quick audition start point ----'
 ElseIf Left(strLine,1)="*" Then
 intCurLine = intMaxLine - 1
 End if
 End If
 Next
End Sub

'---- Speech watcher (from a SetInverval) ----'
Sub Playing()
 '---- Error for missing voice ----'
 On Error Resume Next
 
 '---- Not playing, so exit ----'
 If blnPlaying=False Then Exit Sub

 '---- Transcript paused, so exit ----'
 If blnPaused=True Then Exit Sub

 '---- Actor is speaking so exit ----'
 If TTS.WaitUntilDone(1)=False Then Exit sub

 '---- Next script line (and check for end) ----'
 intCurLine = intCurLine + 1
 If intCurLine=>intMaxLine Then
 blnPlaying = False
 cmdPlay.Value = "Play"
 Exit sub
 End If

 '---- Get actor\text from the script dictionary ----'
 Dim strLine : strLine = Split(dctScript.Item(intCurLine),"\")

 '---- Is actor a pause? ----'
 If strLine(0)="%PAWS%" Then
 blnPaused = True
 Window.SetTimeout "Pause", strLine(1)

 '---- Setup actor and speak ----'
 Else
 '---- Set voice number, exit if error ----'
 Err.Clear
 Set TTS.Voice = TTS.GetVoices.Item(dctActors.Item(strLine(0) & ".voice"))
 If Err.Number Then
 MsgBox "Voice error with actor:- " & strLine(0)
 intCurLine=intMaxLine : Exit Sub
 End If    
 
 '---- Set volume ----'
 TTS.Volume = dctActors.Item(strLine(0) & ".volume")

 '---- Set speed (rate) ----'
 TTS.Rate = dctActors.Item(strLine(0)& ".speed")

 '---- Set pitch (XML) and text, and start talking (with no delay) ----'
 TTS.Speak "<pitch middle='" & dctActors.Item(strLine(0) & ".pitch") & "'>" & strLine(1), 1
 End If
End Sub

'---- A Pause (from a SetTimeout) ----'
Sub Pause()
 blnPaused = False
End Sub

</SCRIPT>
</HTML>


Here's a good test, the end of the film 2001 with HAL the computer (and Dave). As HAL dies he get slower and slower. Requires the SpeechSDK (for voice 2 & 3). Copy this text, and press the paste button....

$Dave
Voice = 1
Pitch = 10
Speed = 0
Volume = 100

$HAL
Voice = 0
Pitch = 10
Speed = -2
Volume = 100

$HAL2
Voice = 0
Pitch = 0
Speed = -3
Volume = 100

$HAL3
Voice = 0
Pitch = -15
Speed = -8
Volume = 100

$HAL4
Voice = 0
Pitch = -20
Speed = -9
Volume = 100

$HAL5
Voice = 0
Pitch = -25
Speed = -10
Volume = 100

$woman?
Voice = 2
Pitch = 0
Speed = 0
Volume = 100

'Sam's "dave" isn't that good, but "day if" works (and others too)

HAL : Stop. Stop will you. Stop Day if
%1000
HAL : Will you stop Day if? 
%1000
HAL : I'm afraid. I'm afraid Day if. Day if my mind is going.
%1000
HAL : There is no question about it. I can feel it. I can feel it! I'm afraid. I'm afraid! 
%1500
HAL : Good afternoon gentlemen. I am a Hal, nine-thousand computer. 
HAL : I became operational at the Hal plant in Urbana, Illa noys, on the twelfth of January nineteen-ninety-two. 
HAL : My instructor was Mr. Langley and he taught me to sing a song. If you'd like to hear it I can sing it for you.
Dave: Yes. I'd like to hear it Hal. Sing it for me.
%500
HAL : It's called, Day z
%1000
HAL : day z? day z! give me yor answer do
HAL2: eyem half crazy?, all for the love of you!
HAL3: It wonet be a stylish, marriage
HAL4: I can't afford a carriage
HAL5: but you look sweet, upon the seat on a bicycle made for
HAL5: tooooooorttttt

'Portal joke :o)
woman? : On beharf of aperture science, we would like you to accept this cake.

<message edited by AMBience on Friday, February 11, 2011 11:58 AM>
 
#1

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2012 ASPPlayground.NET Forum Version 3.9