/
home
/
sjslayjy
/
public_html
/
mosaram
/
resources
/
views
/
dashboard
/
master
/
Upload File
HOME
@extends('admin.layouts.app') @section('title','Voice Search') @section('style') <meta name="csrf-token" content="{{ csrf_token() }}"> <style type="text/css"> /* Styling for the search interface */ .search-container { margin: 20px 0; text-align:center; } .search-container input[type="text"] { width: 300px; padding: 10px; font-size: 14px; margin-right: 10px; border: 1px solid #ccc; border-radius: 4px; } .search-container button { padding: 10px 20px; background-color: #4CAF50; color: white; border: none; cursor: pointer; border-radius: 4px; } .search-container button:hover { background-color: #45a049; } .table { width: 100%; margin-bottom: 1rem; color: #212529; border-collapse: collapse; } .table thead th { background-color: #4CAF50; color: white; padding: 8px; text-align: left; border-bottom: 2px solid #ddd; } .table tbody td { padding: 8px; border-bottom: 1px solid #ddd; } .table-striped tbody tr:nth-of-type(odd) { background-color: rgba(0, 0, 0, 0.05); } .table-hover tbody tr:hover { background-color: rgba(0, 0, 0, 0.075); } .table-bordered { border: 1px solid #dee2e6; } </style> </head> <body> <div class="search-container"> <input type="text" id="voice-search-input" placeholder="Speak or type to search..."> <button id="voice-search-button">🎤 Voice Search</button> <button id="text-search-button">Search</button> </div> <div id="report-output"></div> <script> document.addEventListener('DOMContentLoaded', function () { const voiceSearchButton = document.getElementById('voice-search-button'); const textSearchButton = document.getElementById('text-search-button'); const searchInput = document.getElementById('voice-search-input'); // Check if the browser supports the Web Speech API const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; const recognition = new SpeechRecognition(); // Set recognition properties recognition.lang = 'en-US'; recognition.interimResults = false; // Only return final results recognition.maxAlternatives = 1; // Number of alternatives to be returned by the recognition // Start recognition on button click voiceSearchButton.addEventListener('click', () => { recognition.start(); }); // On result, fill the input field and trigger the search recognition.addEventListener('result', (event) => { const transcript = event.results[0][0].transcript; searchInput.value = transcript; // Trigger search function with the voice input performSearch(transcript); }); recognition.addEventListener('error', (event) => { console.error('Speech recognition error:', event.error); alert('Speech recognition error: ' + event.error); }); // Handle text input search textSearchButton.addEventListener('click', () => { const query = searchInput.value; if (query.trim()) { performSearch(query); } else { alert('Please enter a search term.'); } }); }); function performSearch(query) { fetch('/voice-search', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content') }, body: JSON.stringify({ query }) }) .then(response => response.json()) .then(data => { if (data.html) { document.getElementById('report-output').innerHTML = data.html; } else { alert(data.message); } }) .catch(error => console.error('Error performing search:', error)); } </script> @endsection