读取 wav 文件作为流文件

huangapple go评论71阅读模式
英文:

Reading wav file as stream file

问题

我正试图读取一个包含M4A和WAV文件的zip文件。我的目标是提取和处理这些音频文件,然后将它们上传到数据库中作为NPY文件。

我不确定我当前的直接从zip存档中读取文件的方法是否合适。我是否应该考虑使用librosa库来专门处理WAV文件?

with zipfile.ZipFile(zip_path) as z:
    audio_files = [file_path for file_path in sorted(z.namelist()) if file_path.endswith('.m4a')]
    for audio_file_path in tqdm(audio_files):
        lines = []
        for line in z.read(audio_file_path):
            lines.append(line)
英文:

I'm attempting to read a zip file containing both M4A and WAV files. My goal is to extract and process these audio files, and then upload them as NPY files to a database.

I'm uncertain whether my current approach of reading the files directly from the zip archive is appropriate. Should I consider using the librosa library specifically for handling the WAV files?

   with zipfile.ZipFile(zip_path) as z:
        audio_files = [file_path for file_path in sorted(z.namelist()) if 
   file_path.endswith('.m4a') ]
   for audio_file_path in tqdm(audio_files):
         lines = []
         for line in z.read(audio_file_path):
                lines.append(line) 

答案1

得分: 1

你似乎更倾向于批处理而不是处理实时音频流。

在这种情况下,您可能更容易先从zip存档中提取音频文件到临时驱动器,然后可以自由地使用librosa或其他适当的音频工具包在临时驱动器上处理音频文件,最后将结果存储到您的数据库。

英文:

It sounds that you're rather doing batch processing than working on real-time audio streams.

In such case you're likely easier off by fist extracting the audio files from zip archive onto temp drive, then you'll have freedom to process your audio files on the temp drive using librosa or whatever appropriate audio toolkits, and finally store the outcome to your database.

huangapple
  • 本文由 发表于 2023年5月17日 08:16:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76267812.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定