use-recognition
v1.5.1
Published
A composition api for SpeechRecognition, supports vue2.0 and vue3.0
Downloads
9
Maintainers
Readme
use-recognition
A composition api for SpeechRecognition, supports vue2.0 and vue3.0
Installing
# use pnpm
$ pnpm install use-recognition
# use npm
$ npm install use-recognition --save
# use yarn
$ yarn add use-recognition
Usage
Use in Vue >=3.0
<script setup>
import { getCurrentInstance, onMounted } from 'vue'
import useRecognition from 'use-recognition'
const recognition = useRecognition({ lang: 'zh_CN' })
onMounted(() => {
recognition.start()
})
useExpose({ recognition })
</script>
Use in Vue 2.7
<script>
import useRecognition from 'use-recognition'
export default {
setup() {
const recognition = useRecognition({ lang: 'zh_CN' })
recognition.start()
return { recognition }
}
}
</script>
Use in Vue <=2.6
Add
@vue/composition-api
to theproject.json
dependencies and run install.
{
"dependencies": {
"@vue/composition-api": "latest"
}
}
// main.js
import Vue from 'vue'
import VueCompositionApi from '@vue/composition-api'
Vue.use(VueCompositionApi)
new Vue({}).$mount('#app')
<script>
import useRecognition from 'use-recognition'
export default {
setup() {
const recognition = useRecognition({ lang: 'zh_CN' })
recognition.start()
return { recognition }
}
}
</script>
Using unpkg CDN
<script src="https://unpkg.com/vue-demi@latest/lib/index.iife.js"></script>
<script src="https://unpkg.com/[email protected]/dist/index.global.prod.js"></script>
Support & Issues
Please open an issue here.