FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log inLog in 


Speech recognization

Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog
View previous topic :: View next topic  
Author Message
archit507



Vishakapatnam
Joined: 24 Oct 2016
Posts: 14

PostPosted: 10 Nov 2016 14:17    Post subject: Reply with quote

Hi Thomas,

Can we do speech recognization like can we convert speech to text using visual prolog and store it in database? If yes, then can you please provide me any document regarding that.
Back to top
View user's profile Send private message
Thomas Linder Puls



Copenhagen, Denmark
Joined: 28 Feb 2000
Posts: 3124

PostPosted: 10 Nov 2016 15:43    Post subject: Reply with quote

Yes, that is possible. But not trivial.

You will have to import the Microsoft SAPI COM component in your project.

Notice that working with COM requires the Commercial Edition.

_________________
Regards Thomas Linder Puls
Prolog Development Center
Back to top
View user's profile Send private message
archit507



Vishakapatnam
Joined: 24 Oct 2016
Posts: 14

PostPosted: 10 Nov 2016 17:06    Post subject: Reply with quote

Thank you for the update. Can you please provide me code regarding speech recognization, so that I can refer and work on that.
Back to top
View user's profile Send private message
Thomas Linder Puls



Copenhagen, Denmark
Joined: 28 Feb 2000
Posts: 3124

PostPosted: 11 Nov 2016 22:28    Post subject: Reply with quote

This recognizes speech from a file:

implement main
    open core, sapiDDI_types

constants
    recognizerId : string = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Recognizers\Tokens\MS-1033-80-DESK".
    grammarId = 123.
    spfei_interest : unsigned64 = spfei_flagcheck + 2 ^ spei_end_sr_stream + 2 ^ spei_recognition.

clauses
    run() :-
        stdio::outputStream:allowNullPointers := true,
        AudioFileName = @"..\test.wav",
        Recognizer = spInprocRecognizer::new(),
        SpToken = spObjectToken::new(),
        RecognizerToken = SpToken:get_ISpObjectToken_import(),
        RecognizerToken:setId(uncheckedConvert(string, null), recognizerId, b_false),
        Recognizer:setRecognizer(RecognizerToken),
        Recognizer:createRecoContext(RecoContext),
        RecoContext:createGrammar(grammarId, Grammar),
        SpStream = spStream::new(),
        SpStream:bindToFile(AudioFileName, spfm_open_readonly, uncheckedConvert(core::nativeGuid, null), uncheckedConvert(waveformatex, null), 0),
        Recognizer:setInput(SpStream:getIUnknown(), 0),
        Grammar:loadDictation("", splo_static),
        Grammar:setDictationState(sprs_active),
        RecoContext:setNotifyWin32Event(),
        RecoContext:setInterest(spfei_interest, spfei_interest),
        try
            eventLoop(RecoContext)
        finally
            Grammar:unloadDictation(),
            Grammar:setDictationState(sprs_inactive),
            Grammar:release(),
            SpStream:release(),
            SpStream:close(),
            RecoContext:release(),
            Recognizer:release()
        end try.

class predicates
    eventLoop : (iSpRecoContext_import RecoContext).
clauses
    eventLoop(RecoContext) :-
        std::repeat(), %+
            RecoContext:waitForNotifyEvent(0xFFFFFFFF),
            RecoContext:getEvents(1, Event, Fetched),
            if Fetched <> 0 then
                handleEvent(Event)
            end if,
            (Fetched = 0 orelse spevent(spei_end_sr_stream, _, _, _, _, _) = Event),
        !.

    eventLoop(_RecoContext).

class predicates
    handleEvent : (sapiDDI_types::spevent Event).
clauses
    handleEvent(sapiDDI_types::spevent(spei_recognition, _ParamType, _StreamNum, _AudioStreamOffset, _WParam, LParam)) :-
        !,
        Native = uncheckedConvert(iSpRecoResult_native, LParam),
        RecoResult = iSpRecoResult_import::new(Native, comMemory::release()),
        RecoResult:getText(0xFFFFFFFF, 0xFFFFFFFF, 1, Text, DisplayAttributes),
        RecoResult:getPhrase(Phrase),
        stdio::writef("Text = %\nDisplayAttributes = %\nPhrase = %\n", toString(Text), DisplayAttributes, Phrase).

    handleEvent(_).

end implement main


_________________
Regards Thomas Linder Puls
Prolog Development Center
Back to top
View user's profile Send private message
archit507



Vishakapatnam
Joined: 24 Oct 2016
Posts: 14

PostPosted: 14 Nov 2016 10:32    Post subject: Reply with quote

Thank you Thomas.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum