我想直接从FTP服务器读取WAV文件(它在我的FTP服务器中),而不用下载到Python中的PC中。有可能吗?如果有,怎么做?在
我试过这个解决方案,但没用。我有.wav音频文件。我想读这个文件并从.wav文件中获取详细信息,如文件大小、字节率等
我可以在本地读取WAV文件的代码:
import struct
from ftplib import FTP
global ftp
ftp = FTP('****', user='user-****', passwd='********')
fin = open("C3.WAV", "rb")
chunkID = fin.read(4)
print("ChunkID=", chunkID)
chunkSizeString = fin.read(4) # Total Size of File in Bytes - 8 Bytes
chunkSize = struct.unpack('I', chunkSizeString) # 'I' Format is to to treat the 4 bytes as unsigned 32-bit inter
totalSize = chunkSize[0]+8 # The subscript is used because struct unpack returns everything as tuple
print("TotalSize=", totalSize)
为了快速实现,您可以使用我的
FtpFile
类:Get files names inside a zip file on FTP server without downloading whole archive
但是代码效率有点低,因为每个
fin.read
都将打开一个新的下载数据连接。在为了更有效地实现,只需一次下载整个头文件(我不知道WAV头的结构,我以下载10kb为例):
^{pr2}$相关问题 更多 >
编程相关推荐