# recordMixin
# Feature Description
Provides voice input functionality with the following features:
- Supports native browser speech recognition
- Provides complete lifecycle events
- Supports Chinese speech recognition
- Automatically handles recognition status
- Error handling mechanism
- Supports custom callback functions
# Import and Usage
// Import recordMixin individually
import { recordMixin } from 'vue-element-ui-x';
export default {
mixins: [recordMixin],
// ...
};
Note
The import method in the following example is to resolve an error during the documentation site's packaging. Under normal circumstances, please import it in the standard way.
# Usage Examples
# Basic Usage
An example of a basic speech recognition feature.
Copy
# Custom Control
Shows how to customize the start and end of speech recognition.
Recognition Status
Copy
# Error Handling
Shows how to handle errors during the speech recognition process.
Copy
# Mixin Properties
Parameter | Description | Type | Default Value |
---|---|---|---|
recordLoading | Speech recognition status | Boolean | false |
recordValue | Recognized text result | String | '' |
recordRecognition | Recognition instance | Object | null |
recordOptions | Configuration options object | Object | { onError: null, onStart: null, onEnd: null, onResult: null } |
# Mixin Methods
Method Name | Description | Parameters | Return Value |
---|---|---|---|
initRecord | Initialize speech recognition config | options: { onError, onStart, onEnd, onResult } | - |
startRecord | Start speech recognition | - | - |
stopRecord | Stop speech recognition | - | - |
cleanupRecord | Clean up speech recognition resources | - | - |
# Configuration Options
Parameter | Description | Type | Default Value |
---|---|---|---|
onError | Error callback function | Function(error) | null |
onStart | Start callback function | Function | null |
onEnd | End callback function | Function(value) | null |
onResult | Result callback function | Function(results) | null |
# Precautions
- This mixin depends on the browser's
webkitSpeechRecognition
API. Please ensure browser support before use. - Currently, only Chinese speech recognition is supported (lang='zh-CN').
- Resources are automatically cleaned up when the component is destroyed.
- It is recommended to perform browser compatibility checks during development.
- This feature must be used in an HTTPS environment or a localhost development environment.