{"id":14704,"date":"2023-03-07T22:28:10","date_gmt":"2023-03-07T14:28:10","guid":{"rendered":"http:\/\/139.9.1.231\/?p=14704"},"modified":"2023-03-07T22:28:12","modified_gmt":"2023-03-07T14:28:12","slug":"torchaudio","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2023\/03\/07\/torchaudio\/","title":{"rendered":"torchaudio"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"948\" height=\"219\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/03\/image-10.png\" alt=\"\" class=\"wp-image-14710\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/03\/image-10.png 948w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/03\/image-10-300x69.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2023\/03\/image-10-768x177.png 768w\" sizes=\"(max-width: 948px) 100vw, 948px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center has-light-pink-background-color has-background\"><strong>\u5b98\u7f51\uff1a<a href=\"https:\/\/pytorch.org\/audio\/stable\/torchaudio.html\">https:\/\/pytorch.org\/audio\/stable\/torchaudio.html<\/a><\/strong><\/p>\n\n\n\n<p>          Torchaudio is a library for audio and signal processing with PyTorch. It provides I\/O, signal and data processing functions, datasets, model implementations and application components.<\/p>\n\n\n\n<p>\u8bfb\u53d6\u97f3\u9891\uff1a<\/p>\n\n\n\n<p>   \u4f7f\u7528 torchaudio.load \u52a0\u8f7d\u97f3\u9891\u6570\u636e\u3002torchaudio.load \u652f\u6301\u7c7b\u8def\u5f84\u5bf9\u8c61\u548c\u7c7b\u6587\u4ef6\u5bf9\u8c61\u3002\u8fd4\u56de\u503c\u662f\u6ce2\u5f62\uff08tensor\uff09\u548c\u91c7\u6837\u7387\uff08int\uff09\u7684\u5143\u7ec4\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u751f\u6210\u7684 tensor \u5bf9\u8c61\u7684\u7c7b\u578b\u4e3a torch.float32\uff0c\u5176\u503c\u5728[\u22121.0,1.0][\u22121.0,1.0]\u5185\u6807\u51c6\u5316\u3002<br>waveform, sr = torchaudio.load(filepath, frame_offset=0 , num_frames=-1, normalize=True, channels_first=True)<br>\u53c2\u6570\uff1a<\/p>\n\n\n\n<p>filepath (str): \u539f\u59cb\u97f3\u9891\u6587\u4ef6\u8def\u5f84\uff1b<br>frame_offset (int): \u5728\u6b64\u4e4b\u540e\u5f00\u59cb\u8bfb\u53d6\uff0c\u9ed8\u8ba4\u4e3a0\uff0c\u4ee5\u5e27\u4e3a\u5355\u4f4d\uff1b<br>num_frames (int): \u8bfb\u53d6\u7684\u6700\u5927\u5e27\u6570\u3002\u9ed8\u8ba4\u662f-1\uff0c\u5219\u8868\u793a\u4eceframe_offset\u76f4\u5230\u672b\u5c3e\u3002\u5982\u679c\u7ed9\u5b9a\u6587\u4ef6\u4e2d\u6ca1\u6709\u8db3\u591f\u7684\u5e27\uff0c\u8fd9\u4e2a\u51fd\u6570\u53ef\u80fd\u4f1a\u8fd4\u56de\u5b9e\u9645\u5269\u4f59\u7684\u5e27\u6570\u3002<br>normalize (bool): \u5f53\u4e3aTrue\u65f6\uff0c\u8be5\u51fd\u6570\u603b\u662f\u8fd4\u56defloat32\uff0c\u5e76\u4e14\u6240\u6709\u7684\u503c\u88ab\u5f52\u4e00\u5316\u5230[-1,1]\u3002\u5982\u679c\u8f93\u5165\u6587\u4ef6\u662fwav\uff0c\u4e14\u662f\u6574\u5f62\uff0c\u82e5\u4e3aFalse\u65f6\uff0c\u5219\u4f1a\u8f93\u51faint\u7c7b\u578b\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8be5\u53c2\u6570\u4ec5\u5bf9wav\u7c7b\u578b\u7684\u6587\u4ef6\u8d77\u4f5c\u7528\uff0c \u9ed8\u8ba4\u662fTrue\uff1b<br>channels_first (bool)\u2014\u5f53\u4e3aTrue\u65f6\uff0c\u8fd4\u56de\u7684Tensor\u7684\u7ef4\u5ea6\u662f[channel, time]\u3002\u5426\u5219\uff0c\u7ef4\u6570\u4e3a[time, channel]\uff0c \u9ed8\u8ba4\u662fTrue\u3002<br>\u8fd4\u56de\uff1a<\/p>\n\n\n\n<p>waveform (torch.Tensor): \u5982\u679c\u8f93\u5165\u6587\u4ef6\u662fint\u7c7b\u578b\u7684wav\uff0c\u4e14normalization\u4e3aFalse\uff0c\u5219waveform\u7684\u6570\u636e\u5c31\u4e3aint\u7c7b\u578b\u7684\uff0c\u5426\u5219\u662ffloat32\uff1b\u5982\u679cchannel_first=True\uff0c\u5219waveform.shape=[channel, time]\u3002<br>sr (int): \u91c7\u6837\u7387<br>\u91cd\u91c7\u6837<br>waveform = torchaudio.transforms.Resample(orig_freq=16000, new_freq=16000)(waveform)<br>\u53c2\u6570\uff1a<\/p>\n\n\n\n<p>orig_freq (int, optional): \u539f\u59cb\u91c7\u6837\u7387\uff0c\u9ed8\u8ba4:16000\uff1b<br>new_freq (int, optional): \u8f6c\u6362\u540e\u7684\u91c7\u6837\u7387\uff0c\u9ed8\u8ba4:16000\uff1b<br>resampling_method (str, optional) \u2013 \u91cd\u91c7\u6837\u65b9\u6cd5\uff0c\u9ed8\u8ba4: \u2018sinc_interpolation\u2019\uff1b<br>waveform (torch.Tensor): \u8f93\u5165\u97f3\u9891\u7ef4\u5ea6\u53ef\u4ee5\u662f[channel,time]\uff0c\u4e5f\u53ef\u4ee5\u662f[time, channel]\uff1b<br>\u8fd4\u56de\uff1a<\/p>\n\n\n\n<p>waveform (torch.Tensor): \u8f93\u51fa\u97f3\u9891\u7ef4\u5ea6\u548c\u8f93\u5165\u97f3\u9891\u76f8\u540c\uff0c\u4f46\u7531\u4e8e\u91cd\u91c7\u6837\u4e86\uff0ctime\u7684\u6570\u503c\u4f1a\u4e0d\u540c\uff1b<br>\u4fdd\u5b58\u97f3\u9891<br>torchaudio.save(filepath, src, sample_rate, channels_first)<br>\u53c2\u6570\uff1a<\/p>\n\n\n\n<p>firepath (str or pathlib.Path): \u4fdd\u5b58\u8def\u5f84\uff1b<br>src (torch.Tensor): \u97f3\u9891\u6570\u636e\uff0c\u5fc5\u987b\u662f\u4e8c\u7ef4\u7684\uff1b(\u6ce8\uff1a\u9700\u8981\u8f6c\u5230cpu\u4e0b\u7684tensor\uff09<br>sample_rate(int): \u91c7\u6837\u7387\uff1b<br>channels_first (bool): If True, \u7ef4\u5ea6\u5fc5\u987b\u662f[channel, time]\uff0c\u5426\u5219\u662f[time, channel]\u3002<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b98\u7f51\uff1ahttps:\/\/pytorch.org\/audio\/stable\/torchaudio.html Tor &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2023\/03\/07\/torchaudio\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">torchaudio<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,34],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/14704"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=14704"}],"version-history":[{"count":8,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/14704\/revisions"}],"predecessor-version":[{"id":14714,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/14704\/revisions\/14714"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=14704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=14704"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=14704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}