安卓Flutter分析音频波形

3

我希望创建一个音乐应用程序,其视图类似于SoundCloud,清晰地指的是这个:这个

我想为每个条形创建一个类,类似于:

class Bar {
  const Bar(this.alreadyPlayed, this.index, this.height);

  final bool alreadyPlayed;
  final int index;
  final double height;
}

其中,alreadyPlayed是一个布尔值,用于判断条形图是否应该被涂色或变灰,index是条形图的编号,height是条形图的高度。前两个变量应该不难获取,我的问题是如何获取条形图的高度,即此时音乐的强度。这已经足够了,但如果有人知道如何计算特定频率(例如225 Hz)的强度,那将非常有用。

无论如何,如果有帮助的话,我会添加我尝试达成的伪代码:

// Obtain the mp3 file.
//
// Define a number of bars decided from the song length 
// or from a default, for example, 80.
//
// In a loop that goes from 0 to the number of bars create 
// a Bar Object with the default alreadyPlayed as 0, index 
// as the index and the height as a 0.
// 
// Obtain the intensity of the sound in a way like this: 
// sound[time_in_milliseconds = song_lenght_in_milliseconds / num_of_bars ],
// and then set the height of the bar as the just found intensity.

“我所问的是否可能?”

你有解码MP3文件的经验吗?或者你有相关的库吗?我不知道有没有直接做这个的dart库,这意味着你必须用本地代码实现并通过平台通道连接到Flutter,除非你已经想好了其他方法。 - rmtmckenzie
我发现了一个名为audioplayer插件(https://pub.dartlang.org/packages/audioplayer)的东西,它被用在这个应用程序中:https://www.youtube.com/watch?v=FE7Vtzq52xg,用于类似的范围。但我不知道是否可以使用相同的库来完成此操作。我真的不知道如何解码mp3。您所说的本地代码和使用平台通道连接到Flutter是什么意思? - Fabrizio
嗨。你找到获取波形的解决方案了吗? - Richardd
2个回答

3

看起来你想从音频中生成波形图。你已经尝试过什么了吗?

这里没有简短的答案。你可以开始使用 flutter_ffmpeg从音频生成波形数据。你可以自行决定波形数据的格式。一旦你获得了数据,你可以使用 CustomPaint 在 Flutter 中生成波形图。你可以参考这篇 博客文章 上的示例。示例中使用的波形数据是 JSON 格式。


0

你实现了监听麦克风和绘制波形的功能吗? - Naeem

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接