How can I convert spectrogram data to a tensor (or multidimensional numpy array)?

Shamoon

I am using keras and have:

        corrupted_samples, corrupted_sample_rate = sf.read(
            self.corrupted_audio_file_paths[index])

        frequencies, times, spectrogram = scipy.signal.spectrogram(
            corrupted_samples, corrupted_sample_rate)

As per the docs, this gives:

f (ndarray) - Array of sample frequencies.
t (ndarray) - Array of segment times.
Sxx (ndarray) - Spectrogram of x. By default, the last axis of Sxx corresponds to the segment times.

I assume all of the times will line up, so I don't care about the value of the time (I don't think). The same is true of frequencies. So what I actually need is the values at each time for each frequency, which is given by Sxx (or spectrogram) in my code. I'm unsure how to actually do that. It seems simple though.

wz 98

Based on https://towardsdatascience.com/speech-recognition-analysis-f03ff9ce78e9, the author stated that the spectrogram is a spectro-temporal representation of the sound and show some of the steps of converting wav file to spectogram.

One of the example could be as below:

## Check the sampling rate of the WAV file.
audio_file = './siren_mfcc_demo.wav'


import wave
with wave.open(audio_file, "rb") as wave_file:
    sr = wave_file.getframerate()
print(sr)

audio_binary = tf.read_file(audio_file)

# tf.contrib.ffmpeg not supported on Windows, refer to issue
# https://github.com/tensorflow/tensorflow/issues/8271
waveform = tf.contrib.ffmpeg.decode_audio(audio_binary, file_format='wav', samples_per_second=sr, channel_count=1)
print(waveform.numpy().shape)

signals = tf.reshape(waveform, [1, -1])
signals.get_shape()

# Compute a [batch_size, ?, 128] tensor of fixed length, overlapping windows
# where each window overlaps the previous by 75% (frame_length - frame_step
# samples of overlap).
frames = tf.contrib.signal.frame(signals, frame_length=128, frame_step=32)
print(frames.numpy().shape)

# `magnitude_spectrograms` is a [batch_size, ?, 129] tensor of spectrograms. We
# would like to produce overlapping fixed-size spectrogram patches; for example,
# for use in a situation where a fixed size input is needed.
magnitude_spectrograms = tf.abs(tf.contrib.signal.stft(
    signals, frame_length=256, frame_step=64, fft_length=256))

print(magnitude_spectrograms.numpy().shape)

The method above is referring to https://colab.research.google.com/drive/1Adcy25HYC4c9uSBDK9q5_glR246m-TSx#scrollTo=QTa1BVSOw1Oe

Hope it can help you.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to convert a numpy array of tensors to a tensor?

分類Dev

How can I convert a numpy array to a matrix with counts of occurences?

分類Dev

How can I sort a multidimensional array naturally?

分類Dev

How can i convert a text into an array of useful data?

分類Dev

How to convert pandas data frame to NumPy array?

分類Dev

How can I plot a non-normalized spectrogram in MATLAB?

分類Dev

How can I create and pass as argument a multidimensional ctypes array?

分類Dev

How can I convert an async iterator to an array?

分類Dev

Why Tensorflow error: `failed to convert object of type <class 'dict'> to Tensor` happens and How can I solve it?

分類Dev

How can I convert a cell array into a numeric array in MATLAB?

分類Dev

How can I convert an array name to an array pointer in C?

分類Dev

In Tensorflow How can I add a Tensor to another Tensor with different shape?

分類Dev

How can I push data into an array?

分類Dev

how can i trasfere data object to an array

分類Dev

TensorFlow Dataset: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)

分類Dev

How can I sort a numpy array to find a minimum coordinate?

分類Dev

How can I create a numpy array with shape (0, 2)?

分類Dev

How can I unserialize a numpy array that was cast to a bytestring?

分類Dev

How can I print multidimensional arrays in C?

分類Dev

Convert from socket data to numpy array

分類Dev

How can I convert a comma-separated string to an array?

分類Dev

How can I convert a two column array to a matrix with counts of occurences?

分類Dev

How can I convert this object to an array and access values by key in React?

分類Dev

How can I convert a array.map().toList to a generic type?

分類Dev

How can I get textbox value into array and convert into integer in java

分類Dev

How can I convert this code to return matches in array by substring?

分類Dev

How can I convert data frame of survey responses to a frequency table?

分類Dev

How can I convert an array of arrays to an array of objects, selecting the key from other array?

分類Dev

Numpy: how to convert (256, 256) value image into (256, 256, 1) array of data points and back?

Related 関連記事

  1. 1

    How to convert a numpy array of tensors to a tensor?

  2. 2

    How can I convert a numpy array to a matrix with counts of occurences?

  3. 3

    How can I sort a multidimensional array naturally?

  4. 4

    How can i convert a text into an array of useful data?

  5. 5

    How to convert pandas data frame to NumPy array?

  6. 6

    How can I plot a non-normalized spectrogram in MATLAB?

  7. 7

    How can I create and pass as argument a multidimensional ctypes array?

  8. 8

    How can I convert an async iterator to an array?

  9. 9

    Why Tensorflow error: `failed to convert object of type <class 'dict'> to Tensor` happens and How can I solve it?

  10. 10

    How can I convert a cell array into a numeric array in MATLAB?

  11. 11

    How can I convert an array name to an array pointer in C?

  12. 12

    In Tensorflow How can I add a Tensor to another Tensor with different shape?

  13. 13

    How can I push data into an array?

  14. 14

    how can i trasfere data object to an array

  15. 15

    TensorFlow Dataset: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)

  16. 16

    How can I sort a numpy array to find a minimum coordinate?

  17. 17

    How can I create a numpy array with shape (0, 2)?

  18. 18

    How can I unserialize a numpy array that was cast to a bytestring?

  19. 19

    How can I print multidimensional arrays in C?

  20. 20

    Convert from socket data to numpy array

  21. 21

    How can I convert a comma-separated string to an array?

  22. 22

    How can I convert a two column array to a matrix with counts of occurences?

  23. 23

    How can I convert this object to an array and access values by key in React?

  24. 24

    How can I convert a array.map().toList to a generic type?

  25. 25

    How can I get textbox value into array and convert into integer in java

  26. 26

    How can I convert this code to return matches in array by substring?

  27. 27

    How can I convert data frame of survey responses to a frequency table?

  28. 28

    How can I convert an array of arrays to an array of objects, selecting the key from other array?

  29. 29

    Numpy: how to convert (256, 256) value image into (256, 256, 1) array of data points and back?

ホットタグ

アーカイブ