IMPORTANT: As with most properties of speech, the criteria described below are only going to be useful in relative terms--your script is going to do much better the more specifically it can be trained (either automatically or by you feeding it the appropriate parameters as arguments) for a specific individual in combination with a specific recording setup, since things like amplitude, duration, and formant values are all affected by a variety of factors.
How breathing noises can be distinguished from linguistic speech noises:
- Inhalations and exhalations are usually only excited by aspiration noise, so if there is strong voicing (i.e., regular glottal pulses and a voice bar towards the bottom of the spectrum), it's probably not an inhalation or an exhalation. (EXCEPTIONS: Sometimes an inhalation can include voicing if it's an audible gasp, as when someone is startled. An exhalation can include voicing if it's a groan or a voiced sigh.)
- Non-linguistic breathing, if done through the mouth, is usually characterized by a rather neutral formant structure, with formant values akin to those for a schwa-like vowel. Since the glottis is open, you might see a higher F1 and maybe a higher F2 than for a voiced schwa. (EXCEPTIONS: Sometimes other formant structures might appear, for example if the individual grits her teeth upon inhalation or rounds her lips upon exhalation.)
- If the inhalations/exhalations are through the nose only, there won't be oral formant structure. Instead the noise will be relatively low in amplitude and will be rather diffuse in the spectrum. In that regard it might be difficult to distinguish from fricatives like [f] or [θ] (or from voiceless nasals like the ones found in Icelandic), but it will likely be weaker in intensity than those fricatives.
- Some linguistic speech sounds are characterized by formant structure excited by noise. The aspirated portions of aspirated stops are an example of this, but the period of aspiration will be much shorter for such sounds, and they will be flanked by a burst (short period of frication noise) to the left and voicing to the right. Word-initial [h] is another example, but it too will be shorter than breathing, and its formants will match the formants of the voiced vowel/sonorant following it.
- Breathy releases after vowels or released obstruents at the ends of phrases will probably be the most difficult to untangle from independent breath sounds. In reality, this makes sense, as the end of a phrase can often seamlessly transition into an exhalation. In such cases you will have to look for the formants transitioning from the vowel or consonant values to a more neutral schwa-like structure as well as the fading out of the voicing (if it's a vowel) or frication noise (if it's an obstruent).
I don't know that there's a surefire way to distinguish inhalation from exhalation. If anything, it's a bit easier to distinguish them from one another if they are side by side rather than if one instance of either inhalation or exhalation appears in isolation.
- In general, for the same level of "excitedness" on the part of the
speaker (I'm trying to avoid using "intensity" here, to avoid
terminological confusion), the exhalations will appear louder (have
greater amplitude in the waveform) than the inhalations. (EXCEPTIONS:
If someone gasps really forcefully, as when startled or scared, then releases the air more slowly and quietly, the relative amplitudes of the two may be reversed.)
- You may see more low frequency noise in the spectrogram for
exhalations, depending on the recording setup, since exhalations can
cause wind noise across the mic (EXCEPTIONS: The low-frequency wind noise may be less apparent if there is a wind screen or a pop filter over the mic, or if it is a lav mic under the speaker's clothing.)
- If there is an extended period of just normal breathing, as when an individual is listening or just waiting to speak, there will be less time between inhalation and exhalation than between exhalation and subsequent inhalation. (inhale-exhale... inhale-exhale... etc.)