VoiceSpeaker

Just starting out? Need help? Post your questions and find answers here.
incaroad
User
User
Posts: 35
Joined: Sat Apr 20, 2013 2:58 pm
Location: Hungary; Pilisvörösvár

VoiceSpeaker

Post by incaroad »

Hi everybody!
Where did I go wrong this program?

VoiceSpeaker dll file:
https://forum.unity3d.com/attachments/v ... zip.12430/

Code: Select all

Prototype.i ProtoVoiceAvailable()
  If OpenLibrary(0, "Voice_speaker.dll")
    VoiceAvailable.ProtoVoiceAvailable = GetFunction(0, "VoiceAvailable")
  EndIf
  
  Prototype.i ProtoInitVoice()
  If OpenLibrary(0, "Voice_speaker.dll")
    InitVoice.ProtoInitVoice = GetFunction(0, "InitVoice")
  EndIf
  
  
  Prototype.i ProtoWaitUntilDone(millisec.i)
  If OpenLibrary(0, "Voice_speaker.dll")
    WaitUntilDone.ProtoWaitUntilDone = GetFunction(0, "WaitUntilDone")
  EndIf
  
  Prototype.i ProtoFreeVoice()
  If OpenLibrary(0, "Voice_speaker.dll")
    FreeVoice.ProtoFreeVoice = GetFunction(0, "FreeVoice")
  EndIf
  
  Prototype.i ProtoGetVoiceCount()
  If OpenLibrary(0, "Voice_speaker.dll")
    GetVoiceCount.ProtoGetVoiceCount = GetFunction(0, "GetVoiceCount")
  EndIf
  
  Prototype.s ProtoGetVoiceName(index.i)
  If OpenLibrary(0, "Voice_speaker.dll")
    GetVoiceName.ProtoGetVoiceName = GetFunction(0, "GetVoiceName")
  EndIf
  
  Prototype.i ProtoSetVoice(index.i)
  If OpenLibrary(0, "Voice_speaker.dll")
    SetVoice.ProtoSetVoice = GetFunction(0, "SetVoice")
  EndIf
  
  Prototype.i ProtoSay(ttospeak.s)
  If OpenLibrary(0, "Voice_speaker.dll")
    Say.ProtoSay = GetFunction(0, "Say")
  EndIf
  
  
  Prototype.i ProtoSayAndWait(ttospeak.s)
  If OpenLibrary(0, "Voice_speaker.dll")
    SayAndWait.ProtoSayAndWait = GetFunction(0, "SayAndWait")
  EndIf
  
  Prototype.i ProtoSpeakToFile(filename.s, ttospeak.s)
  If OpenLibrary(0, "Voice_speaker.dll")
    SpeakToFile.ProtoSpeakToFile = GetFunction(0, "SpeakToFile")
  EndIf
  
  Prototype.i ProtoGetVoiceState()
  If OpenLibrary(0, "Voice_speaker.dll")
    GetVoiceState.ProtoGetVoiceState = GetFunction(0, "GetVoiceState")
  EndIf
  
  Prototype.i ProtoGetVoiceVolume()
  If OpenLibrary(0, "Voice_speaker.dll")
    GetVoiceVolume.ProtoGetVoiceVolume = GetFunction(0, "GetVoiceVolume")
  EndIf
  
  Prototype.i ProtoSetVoiceVolume(volume.i)
  If OpenLibrary(0, "Voice_speaker.dll")
    SetVoiceVolume.ProtoSetVoiceVolume = GetFunction(0, "SetVoiceVolume")
  EndIf
  
  Prototype.i ProtoGetVoiceRate()
  If OpenLibrary(0, "Voice_speaker.dll")
    GetVoiceRate.ProtoGetVoiceRate = GetFunction(0, "GetVoiceRate")
  EndIf
  
  Prototype.i ProtoSetVoiceRate(rate.i)
  If OpenLibrary(0, "Voice_speaker.dll")
    SetVoiceRate.ProtoSetVoiceRate = GetFunction(0, "SetVoiceRate")
  EndIf
  
  Prototype.i ProtoPauseVoice()
  If OpenLibrary(0, "Voice_speaker.dll")
    PauseVoice.ProtoPauseVoice = GetFunction(0, "PauseVoice")
  EndIf
  
  Prototype.i ProtoResumeVoice()
  If OpenLibrary(0, "Voice_speaker.dll")
    ResumeVoice.ProtoResumeVoice = GetFunction(0, "ResumeVoice")
  EndIf
  
  ;MessageRequester("cím",a$)
  
  
  
  If VoiceAvailable()>0
    
  InitVoice()
 SetVoice(0)
 SetVoiceRate(2)
 SetVoiceVolume(90)
 Say("One, two, three, four, five")
  
EndIf
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: VoiceSpeaker

Post by ts-soft »

I have no documentation, so i can't say all is correct, but it works!

Code: Select all

EnableExplicit

Prototype InitVoice()
Prototype WaitUntilDone(millisec)
Prototype FreeVoice()
Prototype SetVoice(index)
Prototype SetVoiceRate(rate)
Prototype SetVoiceVolume(volume)
Prototype Say(tospeak.p-ascii)

Define dll = OpenLibrary(#PB_Any, "Voice_speaker.dll")
If dll
  Define InitVoice.InitVoice = GetFunction(dll, "InitVoice")
  Define WaitUntilDone.WaitUntilDone = GetFunction(dll, "WaitUntilDone")
  Define FreeVoice.FreeVoice = GetFunction(dll, "FreeVoice")
  Define SetVoice.SetVoice = GetFunction(dll, "SetVoice")
  Define SetVoiceRate.SetVoiceRate = GetFunction(dll, "SetVoiceRate")
  Define SetVoiceVolume.SetVoiceVolume = GetFunction(dll, "SetVoiceVolume")
  Define Say.Say = GetFunction(dll, "Say")
EndIf

InitVoice()
SetVoice(1)
SetVoiceRate(2)
SetVoiceVolume(100)
Say("One, two, three, four, five")
WaitUntilDone(5000)
FreeVoice()
CloseLibrary(dll)
MessageRequester("", "")
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
incaroad
User
User
Posts: 35
Joined: Sat Apr 20, 2013 2:58 pm
Location: Hungary; Pilisvörösvár

Re: VoiceSpeaker

Post by incaroad »

Thank you very much! It Works. We can see that I'm beginners. :lol:
dige
Addict
Addict
Posts: 1251
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: VoiceSpeaker

Post by dige »

Nice voice! Are there also other languages available?

Ciao dige
"Daddy, I'll run faster, then it is not so far..."
ebs
Enthusiast
Enthusiast
Posts: 530
Joined: Fri Apr 25, 2003 11:08 pm

Re: VoiceSpeaker

Post by ebs »

This DLL doesn't actually contain any voices; it just uses any SAPI voices you have installed on your PC.

Based on the documentation on the page you linked, here's what I came up with:

Code: Select all

Prototype InitVoice()
Prototype WaitUntilDone(millisec)
Prototype FreeVoice()
Prototype.l GetVoiceCount()
Prototype.l GetVoiceName(Voice.l)
Prototype SetVoice(Index)
Prototype SetVoiceRate(rate)
Prototype SetVoiceVolume(volume)
Prototype Say(tospeak.p-ascii)
Prototype SayAndWait(tospeak.p-ascii)
Prototype PauseVoice()
Prototype ResumeVoice()
Prototype SpeakToFile(Filename.p-ascii, tospeak.p-ascii)

Define dll = OpenLibrary(#PB_Any, "Voice_speaker.dll")
If dll
  Define InitVoice.InitVoice = GetFunction(dll, "InitVoice")
  Define WaitUntilDone.WaitUntilDone = GetFunction(dll, "WaitUntilDone")
  Define FreeVoice.FreeVoice = GetFunction(dll, "FreeVoice")
  Define.l GetVoiceCount.GetVoiceCount = GetFunction(dll, "GetVoiceCount")
  Define.l GetVoiceName.GetVoiceName = GetFunction(dll, "GetVoiceName")
  Define SetVoice.SetVoice = GetFunction(dll, "SetVoice")
  Define SetVoiceRate.SetVoiceRate = GetFunction(dll, "SetVoiceRate")
  Define SetVoiceVolume.SetVoiceVolume = GetFunction(dll, "SetVoiceVolume")
  Define Say.Say = GetFunction(dll, "Say")
  Define SayAndWait.Say = GetFunction(dll, "SayAndWait")
  Define SpeakToFile.SpeakToFile = GetFunction(dll, "SpeakToFile")
  Define PauseVoice.PauseVoice = GetFunction(dll, "PauseVoice")
  Define ResumeVoice.ResumeVoice = GetFunction(dll, "ResumeVoice")
EndIf

InitVoice()

For Voice.l = 0 To GetVoiceCount() - 1
  SetVoice(Voice)
  Debug PeekS(GetVoiceName(Voice))
  SetVoiceRate(2)
  SetVoiceVolume(100)
  SayAndWait("One, two, three, four, five")
  SpeakToFile("Speech" + Str(Voice) + ".wav", "One, two, three, four, five")
Next

FreeVoice()
CloseLibrary(dll)
MessageRequester("", "")
The only problem I found is that the "SpeakToFile" call produces 5 identical files, instead of one file in each voice.

Regards,
Eric
incaroad
User
User
Posts: 35
Joined: Sat Apr 20, 2013 2:58 pm
Location: Hungary; Pilisvörösvár

Re: VoiceSpeaker

Post by incaroad »

Great job Eric. Thank you very much!
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 631
Joined: Fri Dec 04, 2015 9:26 pm

Re: VoiceSpeaker

Post by skinkairewalker »

how can i use this library in X64 pc version ?
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: VoiceSpeaker

Post by dobro »

the same thing as that DLL.
compile this DLL with Purebasic 5.60
do not delete the "*. Lib" file generated

Code: Select all


;to compile in DLL "Say.dll"

ProcedureDll Say(voice,txt.s,vitesse,Volume)
		; Contributor : Traduction en Pure Basic du code de Sapero par Nico
		; Mis en DLL par Dobro
		
		;Installation de la voix française Virginie si celle d'origine ne fonctionne pas
		;http://s242132022.onlinehome.fr/Download/PureBasic/RSSolo4FrenchVirginie.zip
		#CLSCTX_INPROC_SERVER=1
		
		;/Valeur pour SpeechVoiceSpeakFlags
		#SVSFDefault = 0
		#SVSFlagsAsync = 1
		#SVSFPurgeBeforeSpeak = 2
		#SVSFIsFilename = 4
		#SVSFIsXML = 8
		#SVSFIsNotXML = 16
		#SVSFPersistXML = 32
		#SVSFNLPSpeakPunc = 64
		#SVSFNLPMask = 64
		#SVSFVoiceMask = 127
		#SVSFUnusedFlags = -128
		
		Interface ISpeechObjectToken Extends IDispatch
				get_Id( ObjectId)
				get_DataKey( ISpeechDataKey.l)
				get_Category( ISpeechObjectTokenCategory.l)
				GetDescription( Locale.l,Description)
				SetId( Id,CategoryID,CreateIfNotExist)
				GetAttribute( AttributeName,*AttributeValue)
				CreateInstance( pUnkOuter,SpeechTokenContext,Object)
				Remove( ObjectStorageCLSID)
				GetStorageFileName( ObjectStorageCLSID,KeyName,FileName,SpeechTokenShellFolder,*FilePath)
				RemoveStorageFileName( ObjectStorageCLSID,KeyName,DeleteFile)
				IsUISupported( TypeOfUI,*ExtraData,*Object,*Supported)
				DisplayUI( hWnd,Title,TypeOfUI,*ExtraData,*Object )
				MatchesAttributes( Attributes,*Matches)
		EndInterface
		
		Interface ISpeechObjectTokens Extends IDispatch
				get_Count(a.l)
				Item(Index.l,Token.ISpeechObjectToken)
				get__NewEnum(ppEnumVARIANT.IUnknown )
		EndInterface
		
		Interface ISpeechVoice Extends IDispatch
				get_Status(*ISpeechVoiceStatus .l)
				get_Voice(*ISpeechObjectToken)
				put_Voice(*ISpeechObjectToken.l)
				get_AudioOutput(*ISpeechObjectToken.l)
				put_AudioOutput(*ISpeechObjectToken.l)
				get_AudioOutputStream(*ISpeechBaseStream.l)
				put_AudioOutputStream(*ISpeechBaseStream.l)
				get_Rate(long.l)
				put_Rate(long.l)
				get_Volume(long.l)
				put_Volume(long.l)
				put_AllowAudioOutputFormatChangesOnNextSet(VARIANT_BOOL.l)
				get_AllowAudioOutputFormatChangesOnNextSet(VARIANT_BOOL.l)
				get_EventInterests(SpeechVoiceEvents .l)
				put_EventInterests(SpeechVoiceEvents .l)
				put_Priority(SpeechVoicePriority.l)
				get_Priority(SpeechVoicePriority.l)
				put_AlertBoundary(SpeechVoiceEvents.l)
				get_AlertBoundary(SpeechVoiceEvents.l)
				put_SynchronousSpeakTimeout(long.l)
				SynchronousSpeakTimeout(long.l)
				Speak(*Text, SpeechVoiceSpeakFlags.l, long.l)
				SpeakStream(*ISpeechBaseStream, SpeechVoiceSpeakFlags.l, long.l)
				Pause()
				Resume()
				Skip(*Type, NumItems.l, long.l)
				GetVoices(*RequiredAttributes.l, *OptionalAttributes, *ISpeechObjectTokens.l)
				GetAudioOutputs(*RequiredAttributes, *OptionalAttributes, *ISpeechObjectTokens.l)
				WaitUntilDone(msTimeout.l, VARIANT_BOOL.l)
				SpeakCompleteEvent(long.l)
				IsUISupported(*TypeOfUI, *ExtraData.VARIANT, VARIANT_BOOL.l)
				DisplayUI(hWndParent.l, *Title, *TypeOfUI, *ExtraData.VARIANT)
		EndInterface
		
		Texte1.s="SAPI.SpVoice"
		*Tampon1=AllocateMemory((Len(Texte1)+1)*2)
		PokeS(*Tampon1,Texte1,-1,#PB_Unicode)
		
		Texte2.s="{269316D8-57BD-11D2-9EEE-00C04F797396}"
		*Tampon2=AllocateMemory((Len(Texte2)+1)*2)
		PokeS(*Tampon2,Texte2,-1,#PB_Unicode)
		
		If CLSIDFromProgID_(*Tampon1, @Clsid.CLSID)=#S_OK
				
				If CLSIDFromString_(*Tampon2, @Refiid.CLSID)=#S_OK
						
						CoInitialize_(0)
						
						If  CoCreateInstance_(Clsid, #Null, #CLSCTX_INPROC_SERVER, Refiid, @SpeechVoice.ISpeechVoice)=#S_OK       
								
								SpeechVoice\GetVoices(0, 0, @SpeechObjectTokens.ISpeechObjectTokens)
								SpeechObjectTokens\get_Count(@Count)
								
								;Débug : Listing des voix installés
								For a= 0 To Count-1
										SpeechObjectTokens\Item(a,@Token.ISpeechObjectToken)
										Token\GetDescription(0, @Description)
									;;	Debug PeekS(Description,-1,#PB_Unicode)
										Token\Release()
								Next
								
								
								;Sélection du numéro de la voix (0 voix par defaut configurer dans le panneau de configuration)
								SpeechObjectTokens\Item(voice, @Token.ISpeechObjectToken)
								
								;Vitesse d'exécution (0 Normal. Une valeur négative réduit la vitesse. Une valeur positive augmente la vitesse )
								speechvoice\put_Rate(vitesse)
								
								;Paramétrage du volume (0 à  100)
								speechvoice\put_Volume(volume)
								
								;Fin du paramétrage
								SpeechVoice\put_Voice(Token)   
								SpeechObjectTokens\Release()   
								
								;Il est temps de dire quelques chose en français.
								Texte3.s=txt.s
								
								*Tampon3=AllocateMemory((Len(Texte3)+1)*2)
								PokeS(*Tampon3,Texte3,-1,#PB_Unicode)
								
								temp=#SVSFDefault
								bstrText = SysAllocString_(*Tampon3)
								SpeechVoice\Speak(bstrText, 0, @temp)
								SysFreeString_(bstrText)
								
								FreeMemory(*Tampon3)
								
								SpeechVoice\Release()
						EndIf
						
						CoUninitialize_()
				EndIf
		EndIf
		
		FreeMemory(*Tampon1)
		FreeMemory(*Tampon2)
Endprocedure

Proceduredll.s Getvoices()
	#CLSCTX_INPROC_SERVER=1
		
		;/Valeur pour SpeechVoiceSpeakFlags
		#SVSFDefault = 0
		#SVSFlagsAsync = 1
		#SVSFPurgeBeforeSpeak = 2
		#SVSFIsFilename = 4
		#SVSFIsXML = 8
		#SVSFIsNotXML = 16
		#SVSFPersistXML = 32
		#SVSFNLPSpeakPunc = 64
		#SVSFNLPMask = 64
		#SVSFVoiceMask = 127
		#SVSFUnusedFlags = -128
		
		
		
		Texte1.s="SAPI.SpVoice"
		*Tampon1=AllocateMemory((Len(Texte1)+1)*2)
		PokeS(*Tampon1,Texte1,-1,#PB_Unicode)
		
		Texte2.s="{269316D8-57BD-11D2-9EEE-00C04F797396}"
		*Tampon2=AllocateMemory((Len(Texte2)+1)*2)
		PokeS(*Tampon2,Texte2,-1,#PB_Unicode)
		
		If CLSIDFromProgID_(*Tampon1, @Clsid.CLSID)=#S_OK
				
				If CLSIDFromString_(*Tampon2, @Refiid.CLSID)=#S_OK
						
						CoInitialize_(0)
						
						If  CoCreateInstance_(Clsid, #Null, #CLSCTX_INPROC_SERVER, Refiid, @SpeechVoice.ISpeechVoice)=#S_OK       
								
								SpeechVoice\GetVoices(0, 0, @SpeechObjectTokens.ISpeechObjectTokens)
								SpeechObjectTokens\get_Count(@Count)
								
								;Débug : Listing des voix installés
								For a= 0 To Count-1
										SpeechObjectTokens\Item(a,@Token.ISpeechObjectToken)
										Token\GetDescription(0, @Description)
									Sortie.s=Sortie.s+ PeekS(Description,-1,#PB_Unicode)+chr(10)
										Token\Release()
								Next
								EndIf
						
						CoUninitialize_()
				EndIf
		EndIf
		ProcedureReturn Sortie.s
EndProcedure







then use the DLL with:

the voice number corresponds to the position of the voice returned by Getvoices ()

Code: Select all





Import "Say.lib"
		Say(voice,txt.s,vitesse,Volume)
		Getvoices()
Endimport

Debug Peeks(Getvoices()) ; affiche la liste des voix dispo
Voix=0
;;;Say (Voix,"il etait une bergère, et ri , et rond , petit  patapon",0,100) ; in French
Say (Voix,"the voice number corresponds to the position of the voice returned by Getvoices",0,100) 
; Epb
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
dige
Addict
Addict
Posts: 1251
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: VoiceSpeaker

Post by dige »

Great job dobro! Thanks! :D
"Daddy, I'll run faster, then it is not so far..."
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5345
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: VoiceSpeaker

Post by Kwai chang caine »

cool !!! thanks DOBRO 8)
ImageThe happiness is a road...
Not a destination
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: VoiceSpeaker

Post by Dude »

Is this voice DLL free, or public domain, or what? Where can I find out its license?
Post Reply