{
  "id": 170749,
  "title": "[caution][for beginners] librosa.load()",
  "url": "/competitions/birdsong-recognition/discussion/170749",
  "author_name": "",
  "post_date": "2020-07-28T22:43:28.933682100Z",
  "votes": 8,
  "comment_count": 4,
  "views": 0,
  "content": "<h3>Hello everyone.</h3>\n\n<p>I'm going to share something that <strong>confused me</strong> when I was using <code>librosa.load()</code>. <br>\nAs has been pointed out in several notebooks, you need to be careful when using <code>librosa.load()</code>. </p>\n\n<p>See the following example.</p>\n\n<p><code>python\npath_audio = '. /train_audio/aldfly/XC134874.mp3'\nsignal, sr = librosa.load(path_audio)\nprint(f'sampling rate: {sr}') <br>\n&amp;gt;&amp;gt; sampling rate: 22050 <br>\n</code></p>\n\n<p>If you don't give an argument of sr, librosa.load() will load the audio file with the default value of sr=22050.\nThis means that the sampling rate is not accurate. <br>\nI'll check the <code>train.csv</code> for the sampling rate.</p>\n\n<p><code>python\nsr = df_train[df_train.filename=='XC134874.mp3']['sampling_rate'][0]\nprint(sr) <br>\n&amp;gt;&amp;gt; '48000 (Hz)' <br>\n</code></p>\n\n<p>The exact sampling rate of the audio file seems to be 48000 Hz. librosa.load() can easily work around this problem by giving <code>sr=None</code> as an argument.</p>\n\n<p><code>python\nsignal, sr = librosa.load(path_audio, sr=None)\nprint(f'sampling rate: {sr}') <br>\n&amp;gt;&amp;gt; sampling rate: 48000\n</code></p>\n\n<p>&gt; ref: <a href=\"http://man.hubwiz.com/docset/LibROSA.docset/Contents/Resources/Documents/generated/librosa.core.load.html?highlight=load#librosa.core.load\">http://man.hubwiz.com/docset/LibROSA.docset/Contents/Resources/Documents/generated/librosa.core.load.html?highlight=load#librosa.core.load</a></p>\n\n<h3>That's it!</h3>\n\n<h3>arigato !!</h3>\n\n<hr>\n\n<h3>Update</h3>\n\n<p><a href=\"/hidehisaarai1213\">@hidehisaarai1213</a>  commented. (Thank you <a href=\"/hidehisaarai1213\">@hidehisaarai1213</a> !! )</p>\n\n<blockquote>\n  <p>If the original sr and given sr does not match, it performs resampling.</p>\n</blockquote>",
  "messages": [
    {
      "id": "949768",
      "postDate": "07/28/2020 22:43:28",
      "content": "<h3>Hello everyone.</h3>\n\n<p>I'm going to share something that <strong>confused me</strong> when I was using <code>librosa.load()</code>. <br>\nAs has been pointed out in several notebooks, you need to be careful when using <code>librosa.load()</code>. </p>\n\n<p>See the following example.</p>\n\n<p><code>python\npath_audio = '. /train_audio/aldfly/XC134874.mp3'\nsignal, sr = librosa.load(path_audio)\nprint(f'sampling rate: {sr}') <br>\n&amp;gt;&amp;gt; sampling rate: 22050 <br>\n</code></p>\n\n<p>If you don't give an argument of sr, librosa.load() will load the audio file with the default value of sr=22050.\nThis means that the sampling rate is not accurate. <br>\nI'll check the <code>train.csv</code> for the sampling rate.</p>\n\n<p><code>python\nsr = df_train[df_train.filename=='XC134874.mp3']['sampling_rate'][0]\nprint(sr) <br>\n&amp;gt;&amp;gt; '48000 (Hz)' <br>\n</code></p>\n\n<p>The exact sampling rate of the audio file seems to be 48000 Hz. librosa.load() can easily work around this problem by giving <code>sr=None</code> as an argument.</p>\n\n<p><code>python\nsignal, sr = librosa.load(path_audio, sr=None)\nprint(f'sampling rate: {sr}') <br>\n&amp;gt;&amp;gt; sampling rate: 48000\n</code></p>\n\n<p>&gt; ref: <a href=\"http://man.hubwiz.com/docset/LibROSA.docset/Contents/Resources/Documents/generated/librosa.core.load.html?highlight=load#librosa.core.load\">http://man.hubwiz.com/docset/LibROSA.docset/Contents/Resources/Documents/generated/librosa.core.load.html?highlight=load#librosa.core.load</a></p>\n\n<h3>That's it!</h3>\n\n<h3>arigato !!</h3>\n\n<hr>\n\n<h3>Update</h3>\n\n<p><a href=\"/hidehisaarai1213\">@hidehisaarai1213</a>  commented. (Thank you <a href=\"/hidehisaarai1213\">@hidehisaarai1213</a> !! )</p>\n\n<blockquote>\n  <p>If the original sr and given sr does not match, it performs resampling.</p>\n</blockquote>",
      "rawMarkdown": "### Hello everyone.  \nI'm going to share something that **confused me** when I was using `librosa.load()`.  \nAs has been pointed out in several notebooks, you need to be careful when using `librosa.load()`. \n\nSee the following example.\n\n```python\npath_audio = '. /train_audio/aldfly/XC134874.mp3'\nsignal, sr = librosa.load(path_audio)\nprint(f'sampling rate: {sr}')  \n&gt;&gt; sampling rate: 22050  \n```\n\nIf you don't give an argument of sr, librosa.load() will load the audio file with the default value of sr=22050.\nThis means that the sampling rate is not accurate.  \nI'll check the `train.csv` for the sampling rate.\n\n```python\nsr = df_train[df_train.filename=='XC134874.mp3']['sampling_rate'][0]\nprint(sr)  \n&gt;&gt; '48000 (Hz)'  \n```\n\nThe exact sampling rate of the audio file seems to be 48000 Hz. librosa.load() can easily work around this problem by giving `sr=None` as an argument.\n\n```python\nsignal, sr = librosa.load(path_audio, sr=None)\nprint(f'sampling rate: {sr}')  \n&gt;&gt; sampling rate: 48000\n```\n\n\n&gt; ref: http://man.hubwiz.com/docset/LibROSA.docset/Contents/Resources/Documents/generated/librosa.core.load.html?highlight=load#librosa.core.load\n\n### That's it!  \n### arigato !!\n\n--- \n\n### Update \n@hidehisaarai1213  commented. (Thank you @hidehisaarai1213 !! )\n&gt; If the original sr and given sr does not match, it performs resampling.",
      "votes": null
    },
    {
      "id": "949784",
      "postDate": "07/28/2020 23:42:39",
      "content": "<p>If the original sr and given sr does not match, it performs resampling.</p>",
      "rawMarkdown": "If the original sr and given sr does not match, it performs resampling.",
      "votes": null
    },
    {
      "id": "949857",
      "postDate": "07/29/2020 02:46:19",
      "content": "<p><a href=\"/hidehisaarai1213\">@hidehisaarai1213</a> </p>\n\n<p>I guess I should add that to the post. \nI'll add that later.\nThank you !!</p>",
      "rawMarkdown": "hidehisaarai1213 \n\nI guess I should add that to the post. \nI'll add that later.\nThank you !!",
      "votes": null
    },
    {
      "id": "950003",
      "postDate": "07/29/2020 05:49:40",
      "content": "<p>Or you specify None as SR to preserve the original one</p>",
      "rawMarkdown": "Or you specify None as SR to preserve the original one",
      "votes": null
    },
    {
      "id": "950841",
      "postDate": "07/29/2020 17:00:05",
      "content": "<p>Thank you</p>",
      "rawMarkdown": "Thank you",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 949784,
      "author_name": "hidehisaarai1213",
      "author_url": "",
      "post_date": "07/28/2020 23:42:39",
      "content": "<p>If the original sr and given sr does not match, it performs resampling.</p>",
      "votes": null,
      "replies": [
        {
          "id": 949857,
          "author_name": "fkubota",
          "author_url": "",
          "post_date": "07/29/2020 02:46:19",
          "content": "<p><a href=\"/hidehisaarai1213\">@hidehisaarai1213</a> </p>\n\n<p>I guess I should add that to the post. \nI'll add that later.\nThank you !!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 950003,
          "author_name": "snovik1975",
          "author_url": "",
          "post_date": "07/29/2020 05:49:40",
          "content": "<p>Or you specify None as SR to preserve the original one</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 950841,
      "author_name": "priyanshujain218",
      "author_url": "",
      "post_date": "07/29/2020 17:00:05",
      "content": "<p>Thank you</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "949768": "### Hello everyone.  \nI'm going to share something that **confused me** when I was using `librosa.load()`.  \nAs has been pointed out in several notebooks, you need to be careful when using `librosa.load()`. \n\nSee the following example.\n\n```python\npath_audio = '. /train_audio/aldfly/XC134874.mp3'\nsignal, sr = librosa.load(path_audio)\nprint(f'sampling rate: {sr}')  \n&gt;&gt; sampling rate: 22050  \n```\n\nIf you don't give an argument of sr, librosa.load() will load the audio file with the default value of sr=22050.\nThis means that the sampling rate is not accurate.  \nI'll check the `train.csv` for the sampling rate.\n\n```python\nsr = df_train[df_train.filename=='XC134874.mp3']['sampling_rate'][0]\nprint(sr)  \n&gt;&gt; '48000 (Hz)'  \n```\n\nThe exact sampling rate of the audio file seems to be 48000 Hz. librosa.load() can easily work around this problem by giving `sr=None` as an argument.\n\n```python\nsignal, sr = librosa.load(path_audio, sr=None)\nprint(f'sampling rate: {sr}')  \n&gt;&gt; sampling rate: 48000\n```\n\n\n&gt; ref: http://man.hubwiz.com/docset/LibROSA.docset/Contents/Resources/Documents/generated/librosa.core.load.html?highlight=load#librosa.core.load\n\n### That's it!  \n### arigato !!\n\n--- \n\n### Update \n@hidehisaarai1213  commented. (Thank you @hidehisaarai1213 !! )\n&gt; If the original sr and given sr does not match, it performs resampling.",
    "949784": "If the original sr and given sr does not match, it performs resampling.",
    "949857": "hidehisaarai1213 \n\nI guess I should add that to the post. \nI'll add that later.\nThank you !!",
    "950003": "Or you specify None as SR to preserve the original one",
    "950841": "Thank you"
  },
  "source": "meta"
}