You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 line
2.4 KiB

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>CONVO</title>
  7. <style>
  8. body {
  9. margin: 0;
  10. display: flex;
  11. align-items: center;
  12. justify-content: center;
  13. height: 100vh;
  14. flex-direction: column;
  15. }
  16. h1 {
  17. margin-bottom: 20px;
  18. color: rgb(11, 22, 53);
  19. }
  20. #videoPlayer {
  21. display: block;
  22. margin: auto;
  23. }
  24. </style>
  25. <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.4/socket.io.js"></script>
  26. </head>
  27. <body>
  28. <h1>CONVO</h1>
  29. <video id="videoPlayer" width="800" height="800" autoplay="true" controls></video>
  30. <script>
  31. var socket = io.connect('http://' + document.domain + ':' + location.port);
  32. // Sample video URL for continuous loop
  33. var sampleVideoUrl = "{{ url_for('static', filename='Friendly_new.mp4') }}";
  34. // Flag to indicate whether to play the sample video
  35. var playSampleVideo = true;
  36. startListening();
  37. playVideo(sampleVideoUrl, true);
  38. function startListening() {
  39. socket.emit('start_listening', {});
  40. }
  41. // Play the sample video in a loop when the page loads
  42. playVideo(sampleVideoUrl, true);
  43. socket.on('text_received', function(data) {
  44. //var outputTextarea = document.getElementById('output');
  45. //outputTextarea.value = 'Text: ' + data.text + '\nIntent: ' + data.intent;
  46. // Stop playing the sample video
  47. playSampleVideo = false;
  48. // Play the answer video
  49. playVideo(data.video_url, false, function() {
  50. playSampleVideo = true;
  51. playVideo(sampleVideoUrl, true);
  52. });
  53. });
  54. function playVideo(videoUrl, loop, onEndedCallback) {
  55. var videoPlayer = document.getElementById('videoPlayer');
  56. //videoPlayer.controls = false;
  57. videoPlayer.src = videoUrl;
  58. videoPlayer.loop = loop;
  59. videoPlayer.play();
  60. if (onEndedCallback) {
  61. videoPlayer.onended = onEndedCallback;
  62. }
  63. videoPlayer.play();
  64. }
  65. </script>
  66. </body>
  67. </html>