In Star Trek there is little or no mention of the fact that outer space is a vacuum. There is not air to breathe and no matter to provide resistance to a spaceship.
It is interesting to consider the properties of sound waves and the effect of outer space on how we are able to communicate.
Outer space is a vacuum
Outer space is a vacuum. There is no air in outer space. That is why we cannot breathe in outer space. It is also why we cannot speak in outer space.
In the title illustration, there are air particles between the speaker and a human ear. There is a banding pattern of the air molecules. This is the way sound travels: through waves in the air. These waves take the form of a pattern of higher and lower density of air molecules. The sound waves propagate through space by moving through the air this way, in pressure waves.
When the waves reach your ear they are transferred from the ear to the brain in the form of signals sent by nerves. This is how we hear.
Now imagine the air particles in the above picture are gone. Sound can no longer travel through the space between the speaker and the air. This is because sound requires a medium to travel. This is in notable contrast to photons, which can travel through empty space. An example of photons is visible light.
A "ringing" bell in a vacuum makes no sound (Source)
Since outer space has no air, there is no medium through which sound waves can be transferred. This means no sound waves can propagate in outer space.
This brings about what is probably the more interesting question: does it matter what the medium for sound propagation is? The answer is yes!
Propagation of sound waves is dependent on the medium
I'm sure some people have inhaled helium at a party at some point in his/her life in the hopes of achieving a high pitched voice.
In this case the medium for sound propagation is different than usual. Instead of normal air, your lungs are filled with helium. Helium atoms are much lighter than nitrogen and oxygen, which are the most common constituents of air. Heavier gases propagate sound more slowly than light gases.
When a person talks he/she imparts a lot of different wavelengths of sound to the air. Heavier gas molecules propagate the sound more slowly, giving the sound waves a lower frequency than lighter gas molecules. Therefore, the sound waves in helium have a high frequency (squeaky pitch).
Another phenomenon that contributes to the high pitch of a sound propagated by a light gas has to do with resonance.
We experience resonance on a regular basis, though we may not recognize it. Do you like to double bounce people on a trampoline or have you ever pushed somebody on a swing? Both are examples of resonance. Here, timing is important. By pushing or bouncing at the resonant frequency of the swing or trampoline it is possible to make the person swinging (or the other person bouncing on the trampoline) achieve maximal amplitude for the effort you put into pushing or bouncing.
A graph showing the spike in amplitude at the resonant frequency (Source)
In gases like air or helium there are resonant frequencies as well. For heavy gases these resonant frequencies are smaller, corresponding to deeper tones, than they are for lighter gases. Helium is a very light gas and therefore has a high resonant frequency. These resonant frequencies are magnified relative to others by the same effect as you achieve by double bouncing somebody on a trampoline. Thus high pitched sounds are magnified in helium.
How would this affect Star Trek?
Star Trek characters do not (as far as I have seen) float in outer space and try to talk to one another. They do, however, visit foreign planets.
If it were to be perfectly realistic, their voices should change pitch somewhat on each planet, according to the composition of each planet's particular atmosphere.
I accept the assumption that planets which can support humanoid life likely have approximately the same atmospheric composition as earth. However, there is one way to dramatically change the atmosphere: replace nitrogen, which comprises about 79% of the earth's atmosphere, with another inert gas, like Argon or Krypton, which is much heavier. I imagine that all the characters' voices would sound much deeper. It may also be possible for humanoids to live on such a planet. I would like to see an episode address this phenomenon. I think it would be fun!