9 changed files with 166 additions and 86 deletions
@ -1,24 +1,41 @@ |
|||
/** @odoo-module **/ |
|||
import { CommandPalette } from "@web/core/commands/command_palette"; |
|||
import { patch } from "@web/core/utils/patch"; |
|||
import {CommandPalette} from "@web/core/commands/command_palette"; |
|||
import {patch} from "@web/core/utils/patch"; |
|||
import {useService} from "@web/core/utils/hooks"; |
|||
import rpc from 'web.rpc'; |
|||
|
|||
patch(CommandPalette.prototype, '@web/core/commands/command_palette', { |
|||
setup() { |
|||
this._super.apply(); |
|||
this.notification = useService("notification"); |
|||
}, |
|||
//This function is used to recognize the voice
|
|||
async recordVoice(event) { |
|||
if (location.href.includes('http:')){ |
|||
var response = await rpc.query({ |
|||
model: 'voice.recognition', |
|||
method: 'recognize_speech', |
|||
args: [,], |
|||
}) |
|||
if (response){ |
|||
if (location.href.includes('http:')) { |
|||
const closeFun = this.notification.add( |
|||
"Recording....", |
|||
{ |
|||
title: "Recording", |
|||
type: "success", |
|||
sticky: true |
|||
}, |
|||
); |
|||
setTimeout(() => closeFun(), 15000) |
|||
var response = await rpc.query({ |
|||
model: 'voice.recognition', |
|||
method: 'recognize_speech', |
|||
args: [], |
|||
}) |
|||
if (response) { |
|||
this.state.searchValue = response |
|||
} |
|||
else{ |
|||
this.state.searchValue = "Your voice could not be recognizing......" |
|||
} else { |
|||
this.notification.add( |
|||
"Couldn't recognize the voice, please try again.", |
|||
{ |
|||
title: "Recording", |
|||
type: "info", |
|||
}, |
|||
) |
|||
} |
|||
} |
|||
}, |
|||
|
@ -1,45 +1,73 @@ |
|||
/** @odoo-module **/ |
|||
|
|||
import { SearchBar } from "@web/search/search_bar/search_bar"; |
|||
import { patch } from "@web/core/utils/patch"; |
|||
import {SearchBar} from "@web/search/search_bar/search_bar"; |
|||
import {patch} from "@web/core/utils/patch"; |
|||
import rpc from 'web.rpc'; |
|||
var microphone = false |
|||
import {useService} from "@web/core/utils/hooks"; |
|||
|
|||
const {useEffect, useState} = owl; |
|||
|
|||
patch(SearchBar.prototype, '@web/search/search_bar/search_bar', { |
|||
setup() { |
|||
this._super(...arguments); |
|||
this.microphone = false; |
|||
this.data = useState({ |
|||
response: false |
|||
}); |
|||
this.notification = useService("notification"); |
|||
useEffect(() => { |
|||
this.onSearchInput(); |
|||
}, () => [this.data.response]); |
|||
}, |
|||
//This function is used to recognize the voice in the search bar
|
|||
async recordVoiceBar(event) { |
|||
this.microphone = true |
|||
if (location.href.includes('http:')){ |
|||
var response = await rpc.query({ |
|||
model: 'voice.recognition', |
|||
method: 'recognize_speech', |
|||
args: [,], |
|||
}) |
|||
if (response){ |
|||
this.response = response |
|||
} |
|||
else{ |
|||
this.response= "False" |
|||
var w_response = confirm("can't recognize try again....") |
|||
|
|||
// Function to recognize the voice in the search bar
|
|||
async recordVoiceBar() { |
|||
this.microphone = true; |
|||
|
|||
if (location.href.includes('http:')) { |
|||
const closeFun = this.notification.add( |
|||
"Recording....", |
|||
{ |
|||
title: "Recording", |
|||
type: "success", |
|||
sticky: true |
|||
}, |
|||
); |
|||
setTimeout(() => closeFun(), 15000) |
|||
try { |
|||
const response = await rpc.query({ |
|||
model: 'voice.recognition', |
|||
method: 'recognize_speech', |
|||
args: [], |
|||
}); |
|||
this.data.response = response || false; |
|||
if (!response) { |
|||
this.notification.add( |
|||
"Couldn't recognize the voice, please try again.", |
|||
{ |
|||
title: "Recording", |
|||
type: "info", |
|||
}, |
|||
) |
|||
} |
|||
} catch (error) { |
|||
console.error("RPC error: ", error); |
|||
} |
|||
} |
|||
}, |
|||
|
|||
onSearchInput(ev) { |
|||
if (this.microphone == true){ |
|||
if(this.response != "False"){ |
|||
ev.target.value = this.response; |
|||
} |
|||
else{ |
|||
ev.target.value = "Your Voice can't recognize please try again."; |
|||
} |
|||
let query = ev?.target?.value?.trim(); |
|||
|
|||
if (this.microphone && this.data.response) { |
|||
query = this.data.response; |
|||
this.microphone = false; |
|||
} |
|||
const query = ev.target.value |
|||
if (query.trim()) { |
|||
this.computeState({ query, expanded: [], focusedIndex: 0, subItems: [] }); |
|||
|
|||
if (query) { |
|||
this.computeState({query, expanded: [], focusedIndex: 0, subItems: []}); |
|||
} else if (this.items.length) { |
|||
this.resetState(); |
|||
} |
|||
} |
|||
}) |
|||
}); |
|||
|
Loading…
Reference in new issue