Quantizes waveform amplitudes.
(audio, quantization_channels)
| 62 | |
| 63 | |
| 64 | def mu_law_encode(audio, quantization_channels): |
| 65 | '''Quantizes waveform amplitudes.''' |
| 66 | with tf.name_scope('encode'): |
| 67 | mu = tf.to_float(quantization_channels - 1) |
| 68 | # Perform mu-law companding transformation (ITU-T, 1988). |
| 69 | # Minimum operation is here to deal with rare large amplitudes caused |
| 70 | # by resampling. |
| 71 | safe_audio_abs = tf.minimum(tf.abs(audio), 1.0) |
| 72 | magnitude = tf.log1p(mu * safe_audio_abs) / tf.log1p(mu) |
| 73 | signal = tf.sign(audio) * magnitude |
| 74 | # Quantize signal to the specified number of levels. |
| 75 | return tf.to_int32((signal + 1) / 2 * mu + 0.5) |
| 76 | |
| 77 | |
| 78 | def mu_law_decode(output, quantization_channels): |
no outgoing calls