Microphone Controls & Voice Communication
Manage microphone and voice communication features in multiplayer virtual spaces. These controls are essential for creating collaborative environments, virtual meetings, and social interactions within 3D spaces.
setMicrophoneMuteState
setMicrophoneMuteState(mute: boolean, [callback: Function])
Controls the mute state of the user's microphone for voice communication in the virtual space. This affects voice chat with other users in multiplayer environments.
Parameters:
mute: boolean
-true
to mute the microphone,false
to unmute
js
// Mute the microphone
api.setMicrophoneMuteState(true, function(){
console.log('Microphone muted');
// Update UI to show muted state
updateMicrophoneButton(true);
});
// Unmute the microphone
api.setMicrophoneMuteState(false, function(){
console.log('Microphone unmuted');
// Update UI to show unmuted state
updateMicrophoneButton(false);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
isMicrophoneMuted
isMicrophoneMuted([callback: Function])
Returns the current mute state of the user's microphone. Use this to synchronize UI elements and check communication status.
js
api.isMicrophoneMuted(function(isMuted){
console.log('Microphone muted:', isMuted); // true/false
// Update UI based on current state
if (isMuted) {
showMicrophoneMutedIndicator();
} else {
showMicrophoneActiveIndicator();
}
});
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Voice Communication Examples
Toggle Microphone Control:
js
function toggleMicrophone() {
api.isMicrophoneMuted(function(currentlyMuted) {
// Toggle the current state
api.setMicrophoneMuteState(!currentlyMuted, function() {
console.log('Microphone toggled to:', !currentlyMuted ? 'muted' : 'unmuted');
updateMicrophoneUI(!currentlyMuted);
});
});
}
function updateMicrophoneUI(isMuted) {
const micButton = document.getElementById('mic-button');
micButton.textContent = isMuted ? '🔇 Unmute' : '🎤 Mute';
micButton.className = isMuted ? 'muted' : 'active';
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Meeting Controls Integration:
js
// Initialize microphone controls for a virtual meeting
function initializeMeetingControls() {
// Check initial microphone state
api.isMicrophoneMuted(function(isMuted) {
updateMeetingUI(isMuted);
});
// Set up microphone toggle button
document.getElementById('mic-toggle').addEventListener('click', toggleMicrophone);
}
function updateMeetingUI(isMuted) {
const statusIndicator = document.getElementById('mic-status');
statusIndicator.textContent = isMuted ? 'Microphone Off' : 'Microphone On';
statusIndicator.style.color = isMuted ? '#ff4444' : '#44ff44';
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Privacy and Permissions:
js
// Handle microphone permissions and privacy
function handleMicrophonePrivacy() {
// Always start with microphone muted for privacy
api.setMicrophoneMuteState(true, function() {
console.log('Microphone muted by default for privacy');
// Show user they can unmute when ready
showMicrophonePermissionPrompt();
});
}
function showMicrophonePermissionPrompt() {
const prompt = document.createElement('div');
prompt.innerHTML = `
<p>Click to enable your microphone for voice chat</p>
<button onclick="enableMicrophone()">Enable Microphone</button>
`;
document.body.appendChild(prompt);
}
function enableMicrophone() {
api.setMicrophoneMuteState(false, function() {
console.log('Microphone enabled by user');
hideMicrophonePermissionPrompt();
});
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Best Practices
Privacy First:
- Always start with microphone muted by default
- Provide clear visual indicators of microphone state
- Allow users to easily toggle microphone on/off
User Experience:
- Use clear visual and audio cues for microphone state
- Provide keyboard shortcuts for quick mute/unmute
- Consider push-to-talk functionality for better control
Multiplayer Considerations:
- Respect user privacy preferences
- Provide individual volume controls for other users
- Consider spatial audio for realistic voice positioning