Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The toJSON() method of the AudioPlaybackStats interface is a serializer; it returns a JSON representation of the AudioPlaybackStats object.
toJSON()None.
A JSON object that is the serialization of the AudioPlaybackStats object.
In this example, calling stats.toJSON() returns a JSON representation of the AudioPlaybackStats object.
const audioCtx = new AudioContext();
const stats = audioCtx.playbackStats;
// ...
// Log playbackStats JSON
console.log(stats.toJSON());This would log a JSON object like so:
{
"underrunDuration": 0,
"underrunEvents": 0,
"totalDuration": 68.252138,
"averageLatency": 0.01863,
"minimumLatency": 0,
"maximumLatency": 0.018654
}To get a JSON string, you can use JSON.stringify(stats) directly; it will call toJSON() automatically.