[futurebasic] Re: Audio Numbers

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2007 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Tue, 20 Feb 2007 04:27:33 -0500
tedd asked:

>I'm looking for just a simple set of spoken numbers 0-9
>-- anyone have a source?


Wanna source?

Here's some source.

Ken


'~'A
'                           Processor : cpuPPC
'                         Code Format : Carbon
'                             Runtime : Rntm Appearance.Incl
'                            Debugger : No
'                          CALL Req'd : No
'                    No Re-dim'd Vars : Yes
'                     dim'd Vars Only : Yes
'                        Debug Labels : Yes
'                           QB Labels : No
'                       Optimize STR# : Yes
'                 Ary Bounds Checking : Yes
'                       Show Warnings : Yes
'                       Register Vars : Yes
'               Make Line Start Table : No
'~'B

/*

    Demo to produce simple sound files
    using System voices in OS X 10.x

    This demo generates numbers
    for 0 to 9 placed in an
    "Audio Numbers" folder on
    your Desktop

    Generated .aiff files can be
    converted to mp3's in iTunes

    I like the sound of Victoria

    Ken Shmidheiser
    Feb. 20, 2007

*/


include "Tlbx SpeechSynthesis.Incl"

begin globals
dim dynamic gVoices(_maxInt) as str31
end globals

begin enum 1
_mainWnd
end enum

begin enum 1
_voicePop
_buildFolder
_testVoice
end enum

local fn GetSystemVoiceInfo
dim as OSErr              err
dim as VoiceSpec        @ voice
dim as VoiceDescription @ info
dim as short            @ voiceCount, i

err = fn CountVoices ( voiceCount )
long if ( err == _noErr )
gVoices( 0 ) = str$( voiceCount )
for i= 1 to voiceCount
err = fn GetIndVoice ( i, voice )
long if ( err == _noErr )
err = fn GetVoiceDescription( voice,¬
                   info, sizeof(info) )
gVoices(i) = info.name
end if
next i
end if
end fn = err

local fn BuildPopMenu( id as long )
dim as long   i
dim as handle popH

menu id, 0, _enable, ""
for i = 1 to val( gVoices(0) )
menu id, i, _enable, gVoices(i)
next i
popH = fn GetMenuHandle(id)
DeleteMenu(id)
InsertMenu(popH,-1)

end fn

local fn BuildMainWindow
dim as ControlFontStyleRec cfs
dim as WindowAttributes    wa
dim as Rect                r
dim as short             @ setVal

cfs.flags = _kControlUseFontMask_kControlUseJustMask
wa = _kWindowCloseBoxAttribute _kWindowCollapseBoxAttribute

def NewWindowPositionMethod(_kWindowAlertPositionOnMainScreen)
SetRect( r, 0, 0, 355, 98 )
appearance window -_mainWnd, "Audio Numerals",¬
                    @r, _kDocumentWindowClass, wa
def NewWindowPositionMethod(0)
def SetWindowBackground(_kThemeActiveDialogBackgroundBrush,¬
                                                    _zTrue )

SetRect(r, 20, 20, 245, 37)
appearance button _voicePop, _activeBtn,, 101, -1,¬
                            "Select System Voice:",¬
                      @r, _kControlPopupButtonProc
cfs.font = _kControlFontSmallSystemFont
def SetButtonFontStyle(_voicePop, cfs)

SetRect(r, 20, 57, 332, 78)
appearance button _buildFolder, _activeBtn,,,,¬
   "Build Audio Numbers on Desktop with Selected Voice",¬
                            @r, _kControlPushButtonProc
def SetButtonFontStyle(_buildFolder, cfs)

SetRect(r, 253, 20, 332, 37)
appearance button _testVoice, _activeBtn, 0,,,¬
"Test voice...", @r, _kControlBevelButtonNormalBevelProc

appearance window _mainWnd

end fn

local fn GetPopupMenuText$( whichPopup as long )
dim as long    mItem
dim as str31   menuStr
dim as MenuRef popH

mItem = button( whichPopup )
popH  = button( whichPopup, _FBgetControlMenuHandle )
GetMenuItemText( popH, mItem, menuStr )

end fn = menuStr

local fn UnixCommand( cmd as str255 )
dim as str255 s

open "Unix", 2, cmd
do : line input #2, s
until eof (2) : close  2

end fn

local fn TestVoice
dim as str255 cmd

cmd  = ""
cmd  = "say -v "
cmd += fn GetPopupMenuText$(_voicePop)
cmd += " one, two, three, four, five"

fn UnixCommand( cmd )

end fn

local fn BuildNumberFile
dim as long   i
dim as str255 cmd, dir
dim as str31  numArr(9)

numArr(0) = "zero"  :  numArr(1) = "one"
numArr(2) = "two"   :  numArr(3) = "three"
numArr(4) = "four"  :  numArr(5) = "five"
numArr(6) = "six"   :  numArr(7) = "seven"
numArr(8) = "eight" :  numArr(9) = "nine"

dir  = " ~/Desktop/Audio\ Numbers/"
cmd = "mkdir" + dir
fn UnixCommand( cmd )

for i = 0 to 9
cmd  = "say -v "
cmd += fn GetPopupMenuText$(_voicePop)
cmd += " -o" + dir + numArr(i) + ".aiff "
cmd += numArr(i)
fn UnixCommand( cmd )
next i

end fn

local fn DoDialog
dim as Rect r
dim as long ev, id

ev = dialog(0)
id = dialog(ev)

select ev
case _wndClick   : window id
case _wndClose   : end
case _btnClick
select window(_outputWnd)
case _mainWnd
select id
case _buildFolder : fn BuildNumberFile
case _testVoice   : fn TestVoice
end select
end select
end select

end fn

on dialog fn DoDialog

long if ( system(_sysVers) < 1000 )
stop "Demo requires OS X 10.0 or greater"
end
end if

fn GetSystemVoiceInfo
fn BuildPopMenu(101)
fn BuildMainWindow

do
HandleEvents
until gFBQuit