Is it possible to convert multiple signals into a single mel spectrum image?

username: YuhskeHujisaki
cooked: <p>Is it possible to convert multiple signals into a single mel spectrum image?<br>
Currently, I have converted 16 signals to spectrum with a code like equation, but it is 16 images. I would like to convert them into a single mel spectrum image.</p>
<pre><code class="lang-auto">import numpy as np
import matplotlib.pyplot as plt
import soundfile as sf
import torch
import torchaudio

print(torch.__version__)
print(torchaudio.__version__)
!pip install boto3
import io
import os
import tarfile
import tempfile

import boto3
import matplotlib.pyplot as plt
import requests
from botocore import UNSIGNED
from botocore.config import Config
from IPython.display import Audio
from torchaudio.utils import download_asset

SAMPLE_GSM = download_asset("tutorial-assets/steam-train-whistle-daniel_simon.gsm")
SAMPLE_WAV = download_asset("tutorial-assets/Lab41-SRI-VOiCES-src-sp0307-ch127535-sg0042.wav")
SAMPLE_WAV_8000 = download_asset("tutorial-assets/Lab41-SRI-VOiCES-src-sp0307-ch127535-sg0042-8000hz.wav")
waveform, sample_rate = torchaudio.load(SAMPLE_WAV)
def plot_specgram(waveform, sample_rate, title="Spectrogram"):
    waveform = waveform.numpy()
    k = waveform
    for i in range(15):
      waveform = np.concatenate([waveform,k],0)

    num_channels, num_frames = waveform.shape
    
    figure, axes = plt.subplots(num_channels, 1)
    if num_channels == 1:
        axes = [axes]
    for c in range(num_channels):
        axes[c].specgram(waveform[c], Fs=sample_rate)
        if num_channels &gt; 1:
            axes[c].set_ylabel(f"Channel {c+1}")
    figure.suptitle(title)
    plt.show(block=False)
plot_specgram(waveform, sample_rate)
</code></pre>

username: knoriy
cooked: <p>The simplest way to achieve what you want is to combine the audio files together.<br>
For example:</p>
<pre><code class="lang-auto">wav1 = &lt;CAT_meow&gt;; 
wav2 = &lt;DOG_bark&gt;; 
aug_wav = &lt;CAT_meow&gt; + &lt;&lt;DOG_bark&gt;&gt;
</code></pre>
<p>Where <code>aug_wav</code> is the combined waveform, where you have a cat meow and a dog barking</p>
<p>Working example:</p>
<pre><code class="lang-python">import numpy as np
import torchaudio
import matplotlib.pyplot as plt
from torchaudio.utils import download_asset

SAMPLE_GSM = download_asset("tutorial-assets/steam-train-whistle-daniel_simon.gsm")
SAMPLE_WAV = download_asset("tutorial-assets/Lab41-SRI-VOiCES-src-sp0307-ch127535-sg0042.wav")
waveform, sample_rate = torchaudio.load(SAMPLE_WAV)
def plot_specgram(waveform, sample_rate, title="Spectrogram"):
    waveform = waveform.numpy()
    k = waveform
    for i in range(15):
      waveform = np.concatenate([waveform,k],0)

    waveform = waveform.sum(0) # sum along channels
    waveform = np.expand_dims(waveform, 0) # [time] &gt; [1, time]

    num_channels, num_frames = waveform.shape
    
    figure, axes = plt.subplots(num_channels, 1)
    if num_channels == 1:
        axes = [axes]
    for c in range(num_channels):
        axes[c].specgram(waveform[c], Fs=sample_rate)
        if num_channels &gt; 1:
            axes[c].set_ylabel(f"Channel {c+1}")
    figure.suptitle(title)
    plt.show(block=False)
plot_specgram(waveform, sample_rate)
</code></pre>