Trying to use h5p. Speak your answer

Just learned about h5p. I'm trying to use it by embedding it in the scene.
I'm having trouble in making it work. All things work accordingly as per the design, but the mic doesn't pick up the voice. Hoping someone will enlighten me on how to deal with this issue or if there is a better way on how to do the same activity in hype alone.

Speak Your Answer Hype File.zip (1.1 MB)

Speak Your Answer Sample.zip (1.1 MB)

:rotating_light: Please note that we can only address JavaScript questions and issues in the context of Tumult Hype, so please attach a Hype document so others can dig into what you have so far.

Is it ok to post topic like this? I don't actually know if I did put it on the right topic. Thanks for always helping out.

This type of question is entirely fine to post! It is in the context of Hype.

I don't use h5p, but I see at least one major problem is that you probably need to use an iframe that has appropriate permissions for the microphone.

Instead of using an HTML Widget (embedded html iframe) and then adding the <iframe> code, what you can do is make an HTML Widget with the 'specified url' option and use the URL that was referenced in your code for that https://cms.zoni.edu/wp-admin/admin-ajax.php?action=h5p_embed&id=162.

Then in the Identity Inspector, under Additional HTML Attributes, add a key of allow and value of microphone.

Now when you preview it will in fact prompt for the mic.

Nothing seems to happen after that though :slight_smile:... I'm not sure if it should!

1 Like

Again thank you for the quick reply.
I made the adjustment you've said but I'm still having the same issue.
The idea of this activity is, when they say the correct answer the mic picks up the word they said and it will show if its correct or not.

It is working on h5p itself but not when embedded in hype.

Speak Your Answer V2 Exported.zip (1.1 MB)

Speak Your Answer V2 hype file.zip (1.1 MB)

it should look like this if its correct:

and like this if its incorrect:

Again thank you for your help.

Hmm... If I just copy the embed code it gives and put it on an otherwise empty html webpage, I cannot get it to work. Maybe you can work with h5p support and figure out how to properly export it off their site? Once an embed works fine then I imagine it would work in a Hype context.

Never touched this before but the example out there for the speak French recording works.

If I replace the url for that I get your example but yours is not working.

So I do not think the issue is with how it is being embed more either the server you have it on or your files is not right.

I actually made something that work. I have a compilation of what works in h5p.
My issue is the mic repeatedly ask for permission if it's just the html exported file I opened. I even learned how to put it in github :laughing:
There's a lot of error in this project of mine, but for now this is what I'm capable.

H5P Tryouts.zip (129.2 KB)

https://hisenberg21.github.io/h5pzoni/

1 Like

I actually wanted to make this project without any embedding from another website, I mean to I want to make it fully in hype. But it still not possible on my current skill.

1 Like

Actually this is exactly the type of thing I'd use ChatGPT for. Here was its solution:

Combined to a single .html page:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Speech Recognition Test</title>
</head>
<body>
Say "mathematics"
<button id="speakButton">Speak Now</button>
<script>

document.getElementById('speakButton').addEventListener('click', function() {
    // Check if the browser supports speech recognition
    if (!('webkitSpeechRecognition' in window)) {
        alert('Your browser does not support speech recognition. Try Google Chrome.');
        return;
    }

    var recognition = new webkitSpeechRecognition();
    recognition.lang = 'en-US'; // Set the language of the recognition
    recognition.start(); // Start recognition

    recognition.onresult = function(event) {
        var speechResult = event.results[0][0].transcript.toLowerCase(); // Get the transcript
        console.log("Recognized:", speechResult);
        if (speechResult === 'mathematics') {
            alert('Correct');
        } else {
            alert('Wrong');
        }
    };

    recognition.onerror = function(event) {
        console.error('Recognition error', event.error);
        alert('Error occurred in recognition: ' + event.error);
    };
});

</script>
</body>
</html>
2 Likes

Added @Jonathan /ChatGPT to hype.

Speech.hype.zip (30.5 KB)

1 Like

thanks for the reply! I did try to use chatGPT working on this. The problem that I face after is adding another scene that ask a different word to pronounce. Will this work on multiple scene with different words?
Thanks for the help!

It should but with adjustments.

You will need to use conditionals in the code to differentiate between the questions and elements displaying the answers

The score bar and counter could be a persistent symbol.

1 Like

Here is a revised example showing two scenes.
This is just a quick example, here are many ways of differentiating between code/scenes/elements and there are plenty of existing answers on the fora to show how to this and individualise/conditionalise code/scenes/elements

Speech_v2.hype.zip (45.1 KB)

The main code looks like this now and the correct.wrong bar is a persistent symbol

	
	
	// The Answers 
	   const answers_ = ["mathematics","scientific"]
	   
	   
	   // define the correct answer counter
	   if (typeof hypeDocument.customData.correct == "undefined"){
	   hypeDocument.customData.correct = 0
	   }  
	   
	   // using the scene names as a answer index ( we minus 1 later to match against the answers array)
	   var curentScene_number = parseInt(hypeDocument.currentSceneName().split('_')[1]) 
	   console.log("curentScene_number:",curentScene_number)
        
	   
	 // Check if the browser supports speech recognition
    if (!('webkitSpeechRecognition' in window)) {
        alert('Your browser does not support speech recognition. Try Google Chrome.');
        return;
        }
        
        // get the text display and symbol timeline.
     
    var recText_  = document.querySelector('.recText')
    
    var displatText1_ =  document.querySelector('.displatText1')
	var barText1_ =  document.querySelector('.barText1')
	 
	 var bar_ = hypeDocument.getSymbolInstancesByName('bar')[0]
	
    var recognition = new webkitSpeechRecognition();
    recognition.lang = 'en-US'; // Set the language of the recognition
    recognition.start(); // Start recognition

    recognition.onresult = function(event) {
   
        var speechResult = event.results[0][0].transcript.toLowerCase(); // Get the transcript
        
        console.log("Recognized:", speechResult);
        console.log("Answer:",answers_[curentScene_number - 1])
        
        // compare recognised answer to array answer
        recText_.innerHTML =    speechResult
        
        if (speechResult ===  answers_[curentScene_number - 1]) {
          
          // add 1 to the answer counter
          hypeDocument.customData.correct++
          
          displatText1_.innerHTML = 'Correct!'
          
          
          barText1_.innerHTML =  hypeDocument.customData.correct + '/' + curentScene_number
           
          bar_.goToTimeInTimelineNamed(2.06, 'answer1')
          bar_.continueTimelineNamed('answer1', hypeDocument.kDirectionForward, false)
           
        } else {
           displatText1_.innerHTML = 'Wrong!'
           barText1_.innerHTML = hypeDocument.customData.correct + '/' + curentScene_number
           bar_.goToTimeInTimelineNamed(3.0, 'answer1')
           bar_.continueTimelineNamed('answer1', hypeDocument.kDirectionForward, false)
        }
        
        // stop recognising
         recognition.stop();
    };

	 ;
    recognition.onerror = function(event) {
        console.error('Recognition error', event.error);
        alert('Error occurred in recognition: ' + event.error);
    };


Speech_v2.hype.zip (44.8 KB)


Scene 1

--

Scene 2

--

We also have a separate on scene reset js function.


Probably a good idea to have a look at this also, as it will help you with the code and understanding what you may need to do to work with and write it.