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