README
Flow
Demo
1、Call the HTTP interface to obtain the Token
2.create WebSocket
talkNode
标题 | |
---|---|
Default | wss://m1.mettaxiot.com/talk/websocket/ |
india | wss://india.mettaxiot.com/talk/websocket/ |
uae | wss://uae.mettaxiot.com/talk/websocket/ |
southafrica | wss://southafrica.mettaxiot.com/talk/websocket/ |
param
imei
:deviceIdtoken
:from http interfacecallback
:back
msg.data instanceof Blob
: Audio datalet data = JSON.parse(msg.data);
data.code === 'connect'
:Link successfully establisheddata.code === 'repeat'
:Repeated connections indicate that a new user has initiated a conversation with the device, and the current link has expireddata.code === 'release'
:The device has disconnected from the linkdata.code === 'network'
:data.deviceTime is the timestamp of data on the device (related to the time zone set by the device)demo
When the connection is opened, set the 'loading' status to 'true' and print a message to the console. When receiving a message, perform corresponding operations based on the content of the message, such as receiving Blob data, displaying warning messages, or calling callback functions. When the connection is closed or an error occurs, set the 'loading' status to 'false' and print the corresponding message to the console.
Note: The '_this' variable in the example is used to access the external context (i.e.' this') within the callback function within the closure. This is because the 'this' pointer in the callback function may change, so it is usually necessary to save the reference to the external context in a variable for use in the callback function
3.receive audio
Explain
Eplain
-Assuming the 'Recorder' object is an object containing audio processing methods, and 'g711a2wav' is one of the methods used to convert G.711 encoded audio data into WAV format. In practical applications, it is necessary to ensure that the 'Recorder' object and its methods have been correctly implemented and introduced.
-The error handling in the method is relatively simple, only outputting prompt information through the console. In practical applications, more detailed error handling and user feedback may be required.
4.Microphone
Explain
channelCount :1
bitRate:16
sampleRate:16000
demo
The initRecord
method is used to initialize the recording function. It first creates an instance of 'Recorder' and configures the relevant parameters for recording. Among them, 'onProcess' is a callback function that is called during the recording process to perform real-time processing on the recorded audio data. In this example, audio data is passed to _this The RealTimeSendTry
method may be used to send audio data in real-time to a device._this The RealTimeSendTryReset
method is used to reset the environment (possibly in preparation for sending new audio data); The second callback function handles the situation where the recording device fails to open. It will print the error message to the console. If it is because the user does not allow recording, a 'UserNotAllow' prompt will be added before the error message.
Explain
Modified at 2025-02-10 07:40:51