{
  "id": 176688,
  "title": "Resampling example_test_audio to 32kHz - Duration is changing",
  "url": "/competitions/birdsong-recognition/discussion/176688",
  "author_name": "",
  "post_date": "2020-08-23T01:30:35.334073700Z",
  "votes": null,
  "comment_count": 4,
  "views": 0,
  "content": "<p>I wanted to test my model on long soundscape files.</p>\n<p>I could not find anywhere where example_test_audio files (the long soundscape ones) converted into 32kHz resampled version.</p>\n<p>So, I decided to do it on my own. This is my code</p>\n<p>import librosa<br>\nimport soundfile as sf<br>\ntarget_sr = 32000<br>\nfilename = \"D:/Kaggle/birdsong-recognition/code/Testing Environment/input/birdsong-recognition/test_audio/BLKFR-10-CPL_20190611_093000.pt540.mp3\"<br>\ny, sr = librosa.load(filename,sr=target_sr, mono=True)<br>\nfilename = filename.replace(\".mp3\", \".wav\")<br>\nsf.write(filename, data=y, samplerate=target_sr)</p>\n<p>My problem is duration is changing from 453 seconds to 470 seconds (after resampling). This is a problem.</p>\n<p>Where did i go wrong?</p>\n<p>Please redirect me to any discussion where these files are available in 32kHz (if there is one). Thank you</p>\n<p><a href=\"https://www.kaggle.com/radek1\" target=\"_blank\">@radek1</a> I downloaded your files for train data… Can you help me out</p>",
  "messages": [
    {
      "id": "982036",
      "postDate": "08/23/2020 01:30:35",
      "content": "<p>I wanted to test my model on long soundscape files.</p>\n<p>I could not find anywhere where example_test_audio files (the long soundscape ones) converted into 32kHz resampled version.</p>\n<p>So, I decided to do it on my own. This is my code</p>\n<p>import librosa<br>\nimport soundfile as sf<br>\ntarget_sr = 32000<br>\nfilename = \"D:/Kaggle/birdsong-recognition/code/Testing Environment/input/birdsong-recognition/test_audio/BLKFR-10-CPL_20190611_093000.pt540.mp3\"<br>\ny, sr = librosa.load(filename,sr=target_sr, mono=True)<br>\nfilename = filename.replace(\".mp3\", \".wav\")<br>\nsf.write(filename, data=y, samplerate=target_sr)</p>\n<p>My problem is duration is changing from 453 seconds to 470 seconds (after resampling). This is a problem.</p>\n<p>Where did i go wrong?</p>\n<p>Please redirect me to any discussion where these files are available in 32kHz (if there is one). Thank you</p>\n<p><a href=\"https://www.kaggle.com/radek1\" target=\"_blank\">@radek1</a> I downloaded your files for train data… Can you help me out</p>",
      "rawMarkdown": "I wanted to test my model on long soundscape files.\n\nI could not find anywhere where example_test_audio files (the long soundscape ones) converted into 32kHz resampled version.\n\nSo, I decided to do it on my own. This is my code\n\nimport librosa\nimport soundfile as sf\ntarget_sr = 32000\nfilename = \"D:/Kaggle/birdsong-recognition/code/Testing Environment/input/birdsong-recognition/test_audio/BLKFR-10-CPL_20190611_093000.pt540.mp3\"\ny, sr = librosa.load(filename,sr=target_sr, mono=True)\nfilename = filename.replace(\".mp3\", \".wav\")\nsf.write(filename, data=y, samplerate=target_sr)\n\nMy problem is duration is changing from 453 seconds to 470 seconds (after resampling). This is a problem.\n\nWhere did i go wrong?\n\nPlease redirect me to any discussion where these files are available in 32kHz (if there is one). Thank you\n\n@radek1 I downloaded your files for train data... Can you help me out",
      "votes": null
    },
    {
      "id": "982145",
      "postDate": "08/23/2020 05:17:15",
      "content": "<p>And if you keep it that way, does it change?</p>\n<pre><code>import scipy.io.wavfile\nscipy.io.wavfile.write(filename, target_sr, y)\n</code></pre>",
      "rawMarkdown": "And if you keep it that way, does it change?\n```\n\nimport scipy.io.wavfile\nscipy.io.wavfile.write(filename, target_sr, y)\n\n```",
      "votes": null
    },
    {
      "id": "982292",
      "postDate": "08/23/2020 08:24:21",
      "content": "<blockquote>\n  <p>filename = filename.replace(\".mp3\", \".wav\")</p>\n</blockquote>\n<p>I haven't tried running your code, but this looks dangerous</p>",
      "rawMarkdown": "> filename = filename.replace(\".mp3\", \".wav\")\n\nI haven't tried running your code, but this looks dangerous",
      "votes": null
    },
    {
      "id": "982905",
      "postDate": "08/23/2020 19:44:32",
      "content": "<p><a href=\"https://www.kaggle.com/sapr3s\" target=\"_blank\">@sapr3s</a> <a href=\"https://www.kaggle.com/marcogorelli\" target=\"_blank\">@marcogorelli</a>  <strong>Can you guys tell me the duration of \"BLKFR-10-CPL_20190611_093000.pt540.mp3\"</strong></p>\n<p>In Windows Folders it shows 00:07:33 (453 seconds) - i think it is from metadata of that file</p>\n<p>But when i do just this</p>\n<p>target_sr = 32000<br>\ny, sr = librosa.load(filename,sr=target_sr, mono=True)<br>\nprint(len(y)/sr)</p>\n<p>i get 470</p>\n<p>So it is not about writing file… It is about librosa reading file.<br>\nFrom some online research, I learnt it happens if a file is corrupt or wrong metadata</p>\n<p>If the file is actually 470 seconds (if librosa is right)… the example_test_audio_summary should be wrong for different durations towards the end.</p>\n<p>I reproduced the code in my personal computer and kaggle notebook. In both cases i got 470.</p>",
      "rawMarkdown": "sapr3s @marcogorelli  **Can you guys tell me the duration of \"BLKFR-10-CPL_20190611_093000.pt540.mp3\"**\n\nIn Windows Folders it shows 00:07:33 (453 seconds) - i think it is from metadata of that file\n\nBut when i do just this\n\ntarget_sr = 32000\ny, sr = librosa.load(filename,sr=target_sr, mono=True)\nprint(len(y)/sr)\n\ni get 470\n\nSo it is not about writing file... It is about librosa reading file.\nFrom some online research, I learnt it happens if a file is corrupt or wrong metadata\n\nIf the file is actually 470 seconds (if librosa is right)... the example_test_audio_summary should be wrong for different durations towards the end.\n\nI reproduced the code in my personal computer and kaggle notebook. In both cases i got 470.",
      "votes": null
    },
    {
      "id": "982976",
      "postDate": "08/23/2020 22:42:07",
      "content": "<p>The metadata is wrong.. The example_test_audio_summary seems to be legit.. my bad<br>\nThanks for ur time.</p>",
      "rawMarkdown": "The metadata is wrong.. The example_test_audio_summary seems to be legit.. my bad\nThanks for ur time.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 982145,
      "author_name": "sapr3s",
      "author_url": "",
      "post_date": "08/23/2020 05:17:15",
      "content": "<p>And if you keep it that way, does it change?</p>\n<pre><code>import scipy.io.wavfile\nscipy.io.wavfile.write(filename, target_sr, y)\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 982292,
      "author_name": "marcogorelli",
      "author_url": "",
      "post_date": "08/23/2020 08:24:21",
      "content": "<blockquote>\n  <p>filename = filename.replace(\".mp3\", \".wav\")</p>\n</blockquote>\n<p>I haven't tried running your code, but this looks dangerous</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 982905,
      "author_name": "vsvrp1995",
      "author_url": "",
      "post_date": "08/23/2020 19:44:32",
      "content": "<p><a href=\"https://www.kaggle.com/sapr3s\" target=\"_blank\">@sapr3s</a> <a href=\"https://www.kaggle.com/marcogorelli\" target=\"_blank\">@marcogorelli</a>  <strong>Can you guys tell me the duration of \"BLKFR-10-CPL_20190611_093000.pt540.mp3\"</strong></p>\n<p>In Windows Folders it shows 00:07:33 (453 seconds) - i think it is from metadata of that file</p>\n<p>But when i do just this</p>\n<p>target_sr = 32000<br>\ny, sr = librosa.load(filename,sr=target_sr, mono=True)<br>\nprint(len(y)/sr)</p>\n<p>i get 470</p>\n<p>So it is not about writing file… It is about librosa reading file.<br>\nFrom some online research, I learnt it happens if a file is corrupt or wrong metadata</p>\n<p>If the file is actually 470 seconds (if librosa is right)… the example_test_audio_summary should be wrong for different durations towards the end.</p>\n<p>I reproduced the code in my personal computer and kaggle notebook. In both cases i got 470.</p>",
      "votes": null,
      "replies": [
        {
          "id": 982976,
          "author_name": "vsvrp1995",
          "author_url": "",
          "post_date": "08/23/2020 22:42:07",
          "content": "<p>The metadata is wrong.. The example_test_audio_summary seems to be legit.. my bad<br>\nThanks for ur time.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "982036": "I wanted to test my model on long soundscape files.\n\nI could not find anywhere where example_test_audio files (the long soundscape ones) converted into 32kHz resampled version.\n\nSo, I decided to do it on my own. This is my code\n\nimport librosa\nimport soundfile as sf\ntarget_sr = 32000\nfilename = \"D:/Kaggle/birdsong-recognition/code/Testing Environment/input/birdsong-recognition/test_audio/BLKFR-10-CPL_20190611_093000.pt540.mp3\"\ny, sr = librosa.load(filename,sr=target_sr, mono=True)\nfilename = filename.replace(\".mp3\", \".wav\")\nsf.write(filename, data=y, samplerate=target_sr)\n\nMy problem is duration is changing from 453 seconds to 470 seconds (after resampling). This is a problem.\n\nWhere did i go wrong?\n\nPlease redirect me to any discussion where these files are available in 32kHz (if there is one). Thank you\n\n@radek1 I downloaded your files for train data... Can you help me out",
    "982145": "And if you keep it that way, does it change?\n```\n\nimport scipy.io.wavfile\nscipy.io.wavfile.write(filename, target_sr, y)\n\n```",
    "982292": "> filename = filename.replace(\".mp3\", \".wav\")\n\nI haven't tried running your code, but this looks dangerous",
    "982905": "sapr3s @marcogorelli  **Can you guys tell me the duration of \"BLKFR-10-CPL_20190611_093000.pt540.mp3\"**\n\nIn Windows Folders it shows 00:07:33 (453 seconds) - i think it is from metadata of that file\n\nBut when i do just this\n\ntarget_sr = 32000\ny, sr = librosa.load(filename,sr=target_sr, mono=True)\nprint(len(y)/sr)\n\ni get 470\n\nSo it is not about writing file... It is about librosa reading file.\nFrom some online research, I learnt it happens if a file is corrupt or wrong metadata\n\nIf the file is actually 470 seconds (if librosa is right)... the example_test_audio_summary should be wrong for different durations towards the end.\n\nI reproduced the code in my personal computer and kaggle notebook. In both cases i got 470.",
    "982976": "The metadata is wrong.. The example_test_audio_summary seems to be legit.. my bad\nThanks for ur time."
  },
  "source": "meta"
}