#Include "window9.bi"
#Include "fb_chatbot_alfred.bas"
#include "windows.bi"
ShowWindow( GetConsoleWindow() , SW_HIDE )
LoadArrays("database\database-encrypted.txt")
'linux compat
#ifndef BS_DEFPUSHBUTTON
#define BS_DEFPUSHBUTTON 0
#endif
enum GadgetID
giFirst = 100
giOutputEdit
giInputEdit
giTalkButton
giInstruction
'giScrollBarGadget
end enum
enum ShortCutID
siFirst = 1000
siDefKey
end enum
DIM SHARED TTSvoice as STRING
TTSvoice = "Microsoft David Desktop" 'tts female or male voice (or Zira or David)
Dim As HWND hSecondForm
Dim As HWND hMainForm
Dim As Integer event
Dim As String buf
var msg = txtfile("database\instruction.txt")
hSecondForm = openwindow("instructions", 100, 10, 600, 500)
editorgadget(giInstruction,10,10,560,440, msg)
'SetGadgetColor(giInstruction,0,255,3)
SetGadgetColor(giInstruction,50000,0,3)
hMainForm = OpenWindow("Chatbot Alfred v0.1",100,10,800,600)
'SetGadgetFont(,CINT(LoadFont("MS Dialog",12)))
EditorGadget(giOutputEdit,10,10,700,340, "Alferd: " + alfredtime(), 0 ) '"hello dear one i'm here to talk with you on what ever you want", 0 )
SetGadgetFont(giOutputEdit,CINT(LoadFont("MS Dialog",11)))
Readonlyeditor(giOutputEdit,1)
SetTransferTextLineEditorGadget(giOutputEdit,1)
EditorGadget(giInputEdit,10,350,700,190, "", 0 )
SetGadgetFont(giInputEdit,CINT(LoadFont("MS Dialog",11)))
SetTransferTextLineEditorGadget(giInputEdit,1)
ButtonGadget(giTalkButton,720,520,60,30,"Talk" , BS_DEFPUSHBUTTON )
SetFocus(Gadgetid(giInputEdit)) ' focus on the editor 2
UpdateInfoXserver() ' for linux , so that xserver has time to update the information
AddKeyboardShortcut( hMainForm , FVIRTKEY , VK_RETURN , siDefKey )
Sub speak( text as string ptr )
#Ifdef __FB_LINUX__
Shell("espeak-ng -v us-mbrola-2 -s 120 " & chr(34) & *text & chr(34))
#Else
shell("voice -r -1 -n " & Chr(34) & TTSvoice & Chr(34) & " " & Chr(34) & *text & Chr(34))
#endif
End Sub
sub DefaultButtonPressed()
Var text = GetGadgetText(giInputEdit)
Var ans = userQuestion(text)
SetGadgetText(giInputEdit, "")
Var reply = GetGadgetText(giOutputEdit)
SetGadgetText(giOutputEdit,reply + Chr(10) +"You: " + text + Chr(10) + "Alfred: " + ans)
'threadcreate for TTS speak function (sub) shell command
static as any ptr a : if a then ThreadWait(a)
Static as string sTemp : sTemp = ans
a = ThreadCreate( cast(any ptr,@Speak) , @sTemp )
LineScrollEditor(giInputEdit,5)
LineScrollEditor(giOutputEdit,5)
end sub
Do
select case WaitEvent()
case EventMenu
if EventNumber = siDefKey then DefaultButtonPressed()
case EventClose
if EventHwnd()=hSecondForm then
close_window(hSecondForm)
else 'if eventclose = hMainForm then
End
endif
case EventGadget
select case EventNumber
case giTalkButton
DefaultButtonPressed()
end select
end select
Loop