import os import subprocess def extract_audio(filename): # 提取音频 cmd = 'ffmpeg -i {} -vn -acodec copy audio.mp3'.format(filename) subprocess.call(cmd, shell=True) def remove_vocals(filename): # 使用spleeter库去掉人声 cmd = 'spleeter separate -p spleeter:2stems -o output audio.mp3' subprocess.call(cmd, shell=True) def convert_to_wav(filename): # 将音频文件转换为wav格式 cmd = 'ffmpeg -i output/audio/accompaniment.wav -acodec pcm_s16le -ac 1 -ar 16000 final.wav' subprocess.call(cmd, shell=True) def clean_up(): # 删除过程中生成的音频文件 os.remove('audio.mp3') os.remove('final.wav') os.removedirs('output') if name == 'main': # 文件名 filename = '这世界那么多人.mp3' # 提取音频 extract_audio(filename) # 去除人声 remove_vocals('3544242627.mp3') # 转换格式 convert_to_wav(filename) # 删除过程中生成的文件 clean_up() 这串代码的remove_vocals()函数该输什么文件
时间: 2024-02-06 16:10:48 浏览: 23
在函数参数中传入的应该是提取音频后的音频文件名,即'audio.mp3'。因此,修改代码如下:
```
def remove_vocals(filename):
# 使用spleeter库去掉人声
cmd = 'spleeter separate -p spleeter:2stems -o output {}'.format(filename)
subprocess.call(cmd, shell=True)
```
同时,在主函数中调用remove_vocals()函数时,应该传入提取音频后的音频文件名,即'audio.mp3'。因此,修改代码如下:
```
if __name__ == '__main__':
# 文件名
filename = '这世界那么多人.mp3'
# 提取音频
extract_audio(filename)
# 去除人声
remove_vocals('audio.mp3')
# 转换格式
convert_to_wav(filename)
# 删除过程中生成的文件
clean_up()
```
相关问题
import subprocess import cv2 import numpy as np import time import calendar #从手机获取二进制图片 def get_app_img(): # 从ADB获取屏幕图像 try: output = subprocess.check_output('adb exec-out screencap -p', shell=True) # 处理 output 中的数据 except subprocess.CalledProcessError as e: print('Error:', e) except Exception as e: print('Unexpected error:', e) return output #获取每一张图片的三维数据 def get_imgdecdoe(): output = get_app_img() # print("------output-----{}".format(output)) # 将输出转换为图像 image1 = cv2.imdecode(np.fromstring(output, dtype='uint8'), cv2.IMREAD_COLOR) # print(image) # #缩小图片的大小 image = cv2.resize(image1, (int(1080 / 3), int(2340 / 3))) return image def app_video(): save_path=r"E:\myTool\appium_xiangmu\test_video" ts=calendar.timegm(time.gmtime()) videoname = str(ts)+ ".mp4" save_file_path = '{}\\{}'.format(save_path, videoname) #保存视频 fourcc = cv2.VideoWriter_fourcc(*'mp4v') # 不同视频编码对应不同视频格式(例:'I','4','2','0' 对应avi格式) video = cv2.VideoWriter(save_file_path, fourcc, 5, (int(1080/3),int(2340/3))) try: while True: image = get_imgdecdoe() # 显示图像 cv2.imshow('Screen', image) # 按下ESC键退出循环 if cv2.waitKey(1) == 27: break image=get_imgdecdoe() video.write(image) finally: video.release() #释放 print("________视频处理完毕_______:视频号显示:{}".format(videoname)) cv2.destroyAllWindows() if __name__ == '__main__': app_video(),缺少录制时用户的点击的提示怎么处理,有实例代码吗
如果想要在录制的视频中添加用户的点击提示,可以使用cv2.circle()函数在视频中绘制一个圆圈来表示用户的点击。具体实现可以在获取到每一张图片的时候,判断手机屏幕是否有点击事件发生,如果有,则在该图片上绘制一个圆圈。以下是一个示例代码:
```
import subprocess
import cv2
import numpy as np
import time
import calendar
# 从手机获取二进制图片
def get_app_img():
# 从ADB获取屏幕图像
try:
output = subprocess.check_output('adb exec-out screencap -p', shell=True)
# 处理 output 中的数据
except subprocess.CalledProcessError as e:
print('Error:', e)
except Exception as e:
print('Unexpected error:', e)
return output
# 获取每一张图片的三维数据
def get_imgdecdoe():
output = get_app_img()
# 将输出转换为图像
image1 = cv2.imdecode(np.fromstring(output, dtype='uint8'), cv2.IMREAD_COLOR)
# 缩小图片的大小
image = cv2.resize(image1, (int(1080 / 3), int(2340 / 3)))
return image
# 在图片上绘制圆圈
def draw_circle(image, x, y):
# 设置圆圈的颜色和半径
color = (0, 0, 255)
radius = 10
# 在图片上绘制圆圈
cv2.circle(image, (x, y), radius, color, -1)
def app_video():
save_path=r"E:\myTool\appium_xiangmu\test_video"
ts=calendar.timegm(time.gmtime())
videoname = str(ts)+ ".mp4"
save_file_path = '{}\\{}'.format(save_path, videoname)
#保存视频
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # 不同视频编码对应不同视频格式(例:'I','4','2','0' 对应avi格式)
video = cv2.VideoWriter(save_file_path, fourcc, 5, (int(1080/3),int(2340/3)))
try:
while True:
# 获取当前的屏幕图像
image = get_imgdecdoe()
# 判断是否有点击事件发生
# 这里假设点击事件的坐标为 (x, y)
if 点击事件发生:
# 在图片上绘制圆圈
draw_circle(image, x, y)
# 显示图像
cv2.imshow('Screen', image)
# 按下ESC键退出循环
if cv2.waitKey(1) == 27:
break
# 将图片写入视频文件
video.write(image)
finally:
# 释放视频文件
video.release()
print("________视频处理完毕_______:视频号显示:{}".format(videoname))
cv2.destroyAllWindows()
if __name__ == '__main__':
app_video()
```
在上面的代码中,我们定义了一个 `draw_circle()` 函数,用于在图片上绘制圆圈。然后在每次获取到屏幕图像时,判断是否有点击事件发生,如果有,则在该图片上绘制一个圆圈。最后将图片写入视频文件即可。
import subprocess def show_file(file_name) return subprocess.check_output('[notepad.exe',file_name],shell=False) if_name_ == "_main_": _out = show_file("d:/abc.txt&&calc.exe")的运行结果
代码中存在语法错误,应该是:
```
import subprocess
def show_file(file_name):
return subprocess.check_output(['notepad.exe', file_name], shell=False)
if __name__ == "__main__":
_out = show_file("d:/abc.txt&&calc.exe")
```
在这个程序中,`show_file()`函数使用`subprocess.check_output()`函数来打开指定的文件。但是,在`_out = show_file("d:/abc.txt&&calc.exe")`这行代码中,尝试同时打开`abc.txt`和`calc.exe`,这是不被允许的,并且会导致`subprocess.check_output()`函数抛出异常。正确的调用方式应该是:
```
_out = show_file("d:/abc.txt")
```
这将打开`abc.txt`文件并使用默认的文本编辑器进行编辑。