{
  "id": 202755,
  "title": "sample rate flac and wav (tfrecord)",
  "url": "/competitions/rfcx-species-audio-detection/discussion/202755",
  "author_name": "",
  "post_date": "2020-12-11T20:47:27.951853500Z",
  "votes": 3,
  "comment_count": 5,
  "views": 0,
  "content": "<p>Hi, </p>\n<p>I just found out that the audio samples are 1 minute long by playing a flac file. Now reading the flac files, I get arrays of length 1920000 and reading the wav files from the tfrecord files I get arrays of length 2880000. So the sample rate of the flac files is 32000 and that of the wav files if 48000 and not 16000 as described in the competition. Anyone else had the same issue? </p>\n<p>Cheers<br>\n  Erik </p>",
  "messages": [
    {
      "id": "1109567",
      "postDate": "12/11/2020 20:47:27",
      "content": "<p>Hi, </p>\n<p>I just found out that the audio samples are 1 minute long by playing a flac file. Now reading the flac files, I get arrays of length 1920000 and reading the wav files from the tfrecord files I get arrays of length 2880000. So the sample rate of the flac files is 32000 and that of the wav files if 48000 and not 16000 as described in the competition. Anyone else had the same issue? </p>\n<p>Cheers<br>\n  Erik </p>",
      "rawMarkdown": "Hi, \n\nI just found out that the audio samples are 1 minute long by playing a flac file. Now reading the flac files, I get arrays of length 1920000 and reading the wav files from the tfrecord files I get arrays of length 2880000. So the sample rate of the flac files is 32000 and that of the wav files if 48000 and not 16000 as described in the competition. Anyone else had the same issue? \n\nCheers\n  Erik",
      "votes": null
    },
    {
      "id": "1109656",
      "postDate": "12/11/2020 23:27:16",
      "content": "<p>Hello! When you load the data, <strong>you</strong> choose the sample rate. From what I can tell, the data was truly sampled at 48000 Hz, but depending on how your load the data, it'll resample it to a different rate by default.</p>\n<p>Try this: <br>\n<code>librosa.load(fname, sr=48000)</code></p>",
      "rawMarkdown": "Hello! When you load the data, **you** choose the sample rate. From what I can tell, the data was truly sampled at 48000 Hz, but depending on how your load the data, it'll resample it to a different rate by default.\n\nTry this: \n`librosa.load(fname, sr=48000)`",
      "votes": null
    },
    {
      "id": "1110029",
      "postDate": "12/12/2020 11:01:30",
      "content": "<p>At least with SoundFile, as you read the FLAC file it gives both the raw data and the samplerate (I guess from file metadata). The data always has a length of 2880000, and the samplerate given from SoundFile is always 48000. 2880000/48000=60, so I guess it is as Mika A says.</p>",
      "rawMarkdown": "At least with SoundFile, as you read the FLAC file it gives both the raw data and the samplerate (I guess from file metadata). The data always has a length of 2880000, and the samplerate given from SoundFile is always 48000. 2880000/48000=60, so I guess it is as Mika A says.",
      "votes": null
    },
    {
      "id": "1112615",
      "postDate": "12/14/2020 18:39:52",
      "content": "<p>Hi, </p>\n<p>if you are using PyTorch, if you want to preserve the sample rate of the audio, you can do it with <strong>torchaudio</strong> like this:</p>\n<p><code># Import torchaudio</code><br>\n<code>import torchaudio</code></p>\n<p><code># Load the audio</code><br>\n<code>audio, sample_rate = torchaudio.load('&lt;my_audio_file&gt;.flac')</code></p>\n<p><code># Now audio has shape [num_channels, audio_len], and \"sample_rate\" is the original sample rate of the flac.</code></p>\n<p>Best,</p>\n<p>Guglielmo</p>",
      "rawMarkdown": "Hi, \n\nif you are using PyTorch, if you want to preserve the sample rate of the audio, you can do it with **torchaudio** like this:\n\n`# Import torchaudio`\n`import torchaudio`\n\n`# Load the audio`\n`audio, sample_rate = torchaudio.load('<my_audio_file>.flac')`\n\n`# Now audio has shape [num_channels, audio_len], and \"sample_rate\" is the original sample rate of the flac.`\n\nBest,\n\nGuglielmo",
      "votes": null
    },
    {
      "id": "1128364",
      "postDate": "12/27/2020 11:29:28",
      "content": "<p>Is this the reason why reading audio files with sample rate of 48000 is faster than any other sample rate?</p>",
      "rawMarkdown": "Is this the reason why reading audio files with sample rate of 48000 is faster than any other sample rate?",
      "votes": null
    },
    {
      "id": "1143275",
      "postDate": "01/07/2021 20:23:18",
      "content": "<p>Yes, because there is no resampling in that case.</p>",
      "rawMarkdown": "Yes, because there is no resampling in that case.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1109656,
      "author_name": "maltonji",
      "author_url": "",
      "post_date": "12/11/2020 23:27:16",
      "content": "<p>Hello! When you load the data, <strong>you</strong> choose the sample rate. From what I can tell, the data was truly sampled at 48000 Hz, but depending on how your load the data, it'll resample it to a different rate by default.</p>\n<p>Try this: <br>\n<code>librosa.load(fname, sr=48000)</code></p>",
      "votes": null,
      "replies": [
        {
          "id": 1128364,
          "author_name": "spoon69",
          "author_url": "",
          "post_date": "12/27/2020 11:29:28",
          "content": "<p>Is this the reason why reading audio files with sample rate of 48000 is faster than any other sample rate?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1143275,
          "author_name": "cpmpml",
          "author_url": "",
          "post_date": "01/07/2021 20:23:18",
          "content": "<p>Yes, because there is no resampling in that case.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1110029,
      "author_name": "donkeys",
      "author_url": "",
      "post_date": "12/12/2020 11:01:30",
      "content": "<p>At least with SoundFile, as you read the FLAC file it gives both the raw data and the samplerate (I guess from file metadata). The data always has a length of 2880000, and the samplerate given from SoundFile is always 48000. 2880000/48000=60, so I guess it is as Mika A says.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1112615,
      "author_name": "guglielmocamporese",
      "author_url": "",
      "post_date": "12/14/2020 18:39:52",
      "content": "<p>Hi, </p>\n<p>if you are using PyTorch, if you want to preserve the sample rate of the audio, you can do it with <strong>torchaudio</strong> like this:</p>\n<p><code># Import torchaudio</code><br>\n<code>import torchaudio</code></p>\n<p><code># Load the audio</code><br>\n<code>audio, sample_rate = torchaudio.load('&lt;my_audio_file&gt;.flac')</code></p>\n<p><code># Now audio has shape [num_channels, audio_len], and \"sample_rate\" is the original sample rate of the flac.</code></p>\n<p>Best,</p>\n<p>Guglielmo</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1109567": "Hi, \n\nI just found out that the audio samples are 1 minute long by playing a flac file. Now reading the flac files, I get arrays of length 1920000 and reading the wav files from the tfrecord files I get arrays of length 2880000. So the sample rate of the flac files is 32000 and that of the wav files if 48000 and not 16000 as described in the competition. Anyone else had the same issue? \n\nCheers\n  Erik",
    "1109656": "Hello! When you load the data, **you** choose the sample rate. From what I can tell, the data was truly sampled at 48000 Hz, but depending on how your load the data, it'll resample it to a different rate by default.\n\nTry this: \n`librosa.load(fname, sr=48000)`",
    "1110029": "At least with SoundFile, as you read the FLAC file it gives both the raw data and the samplerate (I guess from file metadata). The data always has a length of 2880000, and the samplerate given from SoundFile is always 48000. 2880000/48000=60, so I guess it is as Mika A says.",
    "1112615": "Hi, \n\nif you are using PyTorch, if you want to preserve the sample rate of the audio, you can do it with **torchaudio** like this:\n\n`# Import torchaudio`\n`import torchaudio`\n\n`# Load the audio`\n`audio, sample_rate = torchaudio.load('<my_audio_file>.flac')`\n\n`# Now audio has shape [num_channels, audio_len], and \"sample_rate\" is the original sample rate of the flac.`\n\nBest,\n\nGuglielmo",
    "1128364": "Is this the reason why reading audio files with sample rate of 48000 is faster than any other sample rate?",
    "1143275": "Yes, because there is no resampling in that case."
  },
  "source": "meta"
}