AudioSegment.from_file 参数路径
sound = AudioSegment.from_file("D:/Desktop/mp3/1.MP3", format="mp3")可以正常运行,但是:如果把 路径替换成变量了,则运行出现错误:No such file or directory: 'dir'import base64
import hashlib
import hmac
import json
import os
import time
import requests
import urllib
from pydub import AudioSegment
from pydub.utils import make_chunks
import os, re
dir_path = r'D:/Desktop/mp3/'
fileList=[]
# 输入讯飞开放平台的appid,secret_key和待转写的文件路径
if __name__ == '__main__':
fileList=os.listdir(dir_path)
for fileName in fileList:
print("正在识别:"+fileName)
dir=dir_path+fileName
print("正在识别:"+dir)
sound = AudioSegment.from_file("dir", format="mp3")#你的音频文件的路径
sound_1 = sound[:100000]
sound_2 = sound
sound_1.export("music_1.mp3", format="mp3")
sound_2.export("music_2.mp3", format="mp3")
#print("正在识别2:"+mp3)
wideband 发表于 2023-3-21 10:02
刚才问题提的有问题,是在sound = AudioSegment.from_file("dir", format="mp3") 上边有:
dir不要带上双引号
import base64
import hashlib
import hmac
import json
import os
import time
import requests
import urllib
from pydub import AudioSegment
from pydub.utils import make_chunks
import os, re
dir_path = r'D:/Desktop/mp3/'
fileList=[]
# 输入讯飞开放平台的appid,secret_key和待转写的文件路径
if __name__ == '__main__':
fileList=os.listdir(dir_path)
for fileName in fileList:
print("正在识别:"+fileName)
dir=dir_path+fileName
print("正在识别:"+dir)
sound = AudioSegment.from_file(dir, format="mp3")#你的音频文件的路径
sound_1 = sound[:100000]
sound_2 = sound
sound_1.export("music_1.mp3", format="mp3")
sound_2.export("music_2.mp3", format="mp3")
#print("正在识别2:"+mp3)
刚才问题提的有问题,是在sound = AudioSegment.from_file("dir", format="mp3") 上边有:
dir=dir_path+fileName
页:
[1]