|
| 1 | +--- |
| 2 | +title: Quickstart - Add volume indicator to your Web calling app |
| 3 | +titleSuffix: An Azure Communication Services quickstart |
| 4 | +description: In this quickstart, you'll learn how to add raw media access calling capabilities to your app using Azure Communication Services. |
| 5 | +author: sloanster |
| 6 | + |
| 7 | +ms.author: micahvivion |
| 8 | +ms.date: 1/18/2023 |
| 9 | +ms.topic: quickstart |
| 10 | +ms.service: azure-communication-services |
| 11 | +ms.subservice: calling |
| 12 | +ms.custom: mode-other |
| 13 | +--- |
| 14 | + |
| 15 | +As a developer you can have control over checking microphone volume in Javascript |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | +[!INCLUDE [Public Preview](../../../../includes/public-preview-include-document.md)] |
| 19 | + |
| 20 | +>[!IMPORTANT] |
| 21 | +> The quick start examples here are available starting on the public preview version [1.9.1-beta.1](https://www.npmjs.com/package/@azure/communication-calling/v/1.9.1-beta.1) of the calling Web SDK. Make sure to use that version or newer when trying this quickstart. |
| 22 | +
|
| 23 | +## Checking the audio stream olume |
| 24 | +### Description |
| 25 | + |
| 26 | +As a developer it can be nice to have the ability to check the microphone volume in Javascript. This quickstart shows examples of how to do this in ACS WebJS. |
| 27 | + |
| 28 | +#### Architecture |
| 29 | +##### Pre/Post Call |
| 30 | +ACS Already has raw audio stream access api built over TsCall on Device Manager this can be used to expose audio gain for precall/incall Microphone volume. |
| 31 | +```javascript |
| 32 | +export interface LocalAudioStream { |
| 33 | + getMediaStreamTrack(): Promise<MediaStreamTrack>; |
| 34 | + switchSource(source: AudioDeviceInfo | MediaStreamTrack): Promise<void>; |
| 35 | + dispose(); |
| 36 | +} |
| 37 | +export interface RemoteAudioStream { |
| 38 | + getMediaStreamTrack(): Promise<MediaStreamTrack>; |
| 39 | +} |
| 40 | +``` |
| 41 | +ACS will expose another API on local and remote audio streams to get Microphone volume built over Raw Audio access API, to get Volume (gain) of selected Microphone |
| 42 | +```javascript |
| 43 | +export interface LocalAudioStream { |
| 44 | + getVolume(): Promise<Volume>; |
| 45 | +... |
| 46 | +} |
| 47 | + |
| 48 | +export interface RemoteAudioStream { |
| 49 | + getVolume(): Promise<Volume>; |
| 50 | +... |
| 51 | +} |
| 52 | + |
| 53 | +export interface Volume extends Disposable{ |
| 54 | + off(event: 'levelChanged', listener: PropertyChangedEvent): void; |
| 55 | + on(event: 'levelChanged', listener: PropertyChangedEvent): void; |
| 56 | + readonly level: number; |
| 57 | + } |
| 58 | +``` |
| 59 | +The volume is a number ranging from 0 to 100 |
| 60 | +It's sampled every 200ms to get near realtime value of volume |
| 61 | +#### Example usage |
| 62 | +Sample code to get volume of selected microphone |
| 63 | + |
| 64 | +need call getVolume on audioSourceChanged for local audio stream |
| 65 | + |
| 66 | +```javascript |
| 67 | + |
| 68 | +const volumeIndicator = await new SDK.LocalAudioStream(deviceManager.selectedMicrophone).getVolume(); |
| 69 | +volumeIndicator.on('levelChanged', ()=>{ |
| 70 | + console.log(`Volume is ${volumeIndicator.level}`) |
| 71 | +}) |
| 72 | + |
| 73 | + |
| 74 | +const remoteAudioStream = call.remoteAudioStreams[0]; |
| 75 | +const volumeIndicator = await remoteAudioStream.getVolume(); |
| 76 | +volumeIndicator.on('levelChanged', ()=>{ |
| 77 | + console.log(`Volume is ${volumeIndicator.level}`) |
| 78 | +}) |
| 79 | + |
| 80 | +``` |
| 81 | + |
| 82 | +#### Telemetry for localAudioStream |
| 83 | +best effort to send telemetry, from localAudioStream |
| 84 | +if call client is not initialized before LocalAudioStream, no telemetry will be sent |
| 85 | + |
| 86 | +For MediaStreamTrack telemetry only from the first created call client will be sent |
| 87 | +cc1, new local stream ... everything works fine |
| 88 | +cc1, new local stream gets latched to telemetry logger from cc1, cc2, new local stream will not send data |
0 commit comments