我修剪音频。使用以下代码。
我在 https://pub.dev/packages/audiocutter 中找到代码包裹。
但无法生成输出文件。
import 'package:path_provider/path_provider.dart';
import 'package:ffmpeg_kit_flutter/ffmpeg_kit.dart';
static Future<String> cutAudio(String path, double start, double end) async {
final Directory dir = await getTemporaryDirectory();
final outPath = "${dir.path}/output.mp3";
var cmd = "-y -i \"$path\" -vn -ss $start -to $end -ar 16k -ac 2 -b:a 96k -acodec libmp3lame $outPath";
log(cmd);
FFmpegKit.executeAsync(cmd, (session) async {
final returnCode = await session.getReturnCode();
print("returnCode $returnCode");
});
return outPath;
}
请帮助我如何修剪音频。
最佳答案
我收到此错误是因为输出文件已经存在。
所以我使用删除现有文件解决了这个问题。
我使用以下代码删除了文件。
try {
await File(outPath).delete();
} catch (e) {
print("Delete Error");
}
以下是我的工作代码。static Future<String> cutAudio(String path, double start, double end) async {
final Directory dir = await getTemporaryDirectory();
final outPath = "${dir.path}/output.mp3";
try {
await File(outPath).delete();
} catch (e) {
print("Delete Error");
}
var cmd = "-y -i \"$path\" -vn -ss $start -to $end -ar 16k -ac 2 -b:a 96k -acodec libmp3lame $outPath";
log(cmd);
FFmpegKit.executeAsync(cmd, (session) async {
final returnCode = await session.getReturnCode();
print("returnCode $returnCode");
});
return outPath;
}
关于 flutter 音频修剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70241682/