Accessibility

TechNote (Archived)

Macromedia Flash Communication and Audio

This document describes best practices for using audio with Macromedia Flash and the Macromedia Flash Communication Server.

Introduction

What happens to sound

Sound formats

Sound in Macromedia Flash Video Format (FLV) files

Setting bandwidth

Microphone gain and background noise

Preventing feedback

Handling many users talking

Push-To-Talk applications

Using silence for better audio

Introduction
Often users of a Macromedia Flash application work on a wide variety of network connections. These can range from a 56 Kbps modem to a 100 Mbps LAN. Clients using a network connection with lower bandwidth will not be able to send or receive as much audio data as those on a higher speed network connection.

Developers must carefully design their application to ensure the audio works well. Selecting slower microphone sample rates, using silence and push-to-talk user interfaces can help minimize the amount of audio being sent over the network. Using the proper bandwidth settings for a connection will prevent interruptions in the sound stream.

What happens to sound
Audio is normally first input into Macromedia Flash with sampled microphone data. This data is compressed with a speech compressor, then queued along with other data for transmission to the server. The compression technique is optimized for speech, and it compresses at 512 bytes of 16 bit sound (256 samples) into 64 bytes of data.

The Macromedia Flash client intermixes audio, video, data and command packets in the network stream going to the server. Audio packets are given a high priority since they are the most sensitive real-time data.

Upon arriving at the server, audio packets are passed along to other clients who have subscribed to the audio stream. If the audio stream is being recorded, the data is appended to the file on the server. When sent to subscribing clients, it is again intermingled with other audio, video and data packets.

At the receiving client, the packet is decompressed into standard audio data and played.

When playing a recorded stream, the data is read from the server and passed to the client in the same manner. The server paces the data sent to provide enough data for seamless playback while not flooding the client and network with too much data.

Sound formats
Sound can be sampled a 44.1 kHz, 22.050 kHz, 11.025 kHz, 8.000 kHz and 5.512 kHz. The default is 8 kHz and the compression is designed for this rate. Microphone audio in Macromedia Flash is a single, mono channel. It is compressed using a technique optimized for speech.

For normal microphone (mono) audio, the data bit rate as determined by the Microphone.rate property is as follows:

mic.rate

Sampling rate

Approximate data rate
5 5.512 kHz 1378 bytes/sec, or 11.025 K bits/sec
8 8.000 kHz 2,000 bytes/sec, or 16 K bits/sec
11 11.025 kHz 2756 bytes/sec, or 22.05 K bits/sec
22 22.050 kHz 5,513 bytes/sec, or 44.1 K bits/sec
44 44.100 kHz 11,025 bytes/sec, or 88.2 K bits/sec

Note:The actual required data rate will be slightly higher due to the additional information sent as data headers, network protocol information, and so forth.

Sound in Macromedia Flash Video format (FLV) files
Audio that has been saved as a FLV file may be stereo or monophonic. A stereo sound will have twice the amount of audio as a mono sound.In addition, other compression techniques may be used for FLV files. Sound can be compressed as MP3 data, or compression can be turned off entirely for highest quality.When creating a FLV file, pay attention to the audio settings and allow for different client bandwidths. It may be necessary to create more than one video file, one for low bandwidth and another for higher speeds.

Setting bandwidth
Server-side ActionScript can be used to set the bandwidth of a connection. This will set a limit to the amount of data the server or client will attempt to send over the network. This is essential in combined audio and video applications to prevent video packets from occasionally causing audio glitches.

Microphone gain and background noise
The microphone gain should be set as loud as possible without causing clipping and distortion. Too much gain, however, can also pick up additional background noise.

This should be done by the user with the Flash player settings dialog. The user must right-click on a Macromedia Flash movie, then select the "Settings" item from the pop-up menu. They should adjust the gain slider while speaking so that the audio levels reach the yellow area on the indicator with only occasional or no peaks reaching red.

Background noise can make the audio unpleasant to listen to or increase to a level where actual spoken audio is difficult to understand. The background sound can come from the speaker breathing, bumping the microphone, office equipment, nearby conversations, and so forth. Correctly setting the microphone gain, proper microphone placement, and headphones can lower the background noise.

ThemyMicrophone.gain property can be examined to see the current gain value. This is a read-only property.

Preventing feedback
Users can also turn on echo suppression in the microphone settings dialog. This may help decrease feedback and echo while listening to your own audio.

The ActionScript functionmyMicrophone.useEchoSuppression(true) can also enable echo suppression, but it is advisable to let the user configure their own system for proper operation.

Handling many users talking
People using Macromedia Flash are used to talking on the telephone, and at first a chat or conference application that mimics full-duplex phone conversation seems like a good idea.

As more and more clients are connected, however, the following problems may appear:

Each additional audio stream consumes network bandwidth between the server and client. This increases linearly, as each new connection is a new audio stream to receive.

Each additional audio stream adds exponentially to the server load. Two connected clients require four streams at the server (two in, two out) while five clients require 25 (five in, twenty out).

Background noise for each client is added together. The ambient sounds from multiple microphones can add up to a distracting and unpleasant noise.

Push-To-Talk applications
It's a good idea to design applications so that each client is not constantly broadcasting audio. One way to do this is a Push-To-Talk interface, where users must press a button or key to speak. This helps minimize the amount of audio sent over the network, as well as lowering the background noise level heard on each client.

Using silence for better audio
The microphone can be set to stop sending audio when the user is not speaking. If the microphone gain is set properly, the default silence levels should work correctly. Otherwise, use the functionmyMicrophone.setSilenceLevel( level, timeOut ); to adjust this.

When the microphone stops sending audio during silent periods, there are several benefits. First, less network data is sent to the server and all listening clients. Second, other clients will not hear the broadcast background noise, so the other client that is speaking will be easier to understand.

Summary
Macromedia Flash and the Macromedia Flash Communication Server can easily send audio over a high-speed local connection for a small number of users. Designing an application for a larger network with varying conditions and multiple clients requires more efforts to ensure seamless audio. Proper selection of sound sample rates, application design and bandwidth lets audio be used in more complicated situations.



AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support

Document Details

ID:tn_16447

Products Affected:

flash
flashmediaserver