【问题标题】:Android Flutter Analyze Audio WaveformAndroid Flutter 分析音频波形
【发布时间】:2023-03-21 23:04:01
【问题描述】:

我想创建一个具有类似于 SoundCloud 的视图的音乐应用程序,这个要明确:This

我想为每个栏创建一个这样的类:

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

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

其中 alreadyPlayed 是一个布尔值,指示条形图是应该着色还是变灰,index 是条形图的编号和高度,well 是条形的高度。前两个变量应该不难获取,我的问题是获取bar的高度,即当时音乐的强度。这已经足够了,但如果有人知道如何计算特定频率的强度,例如 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 库,这意味着您必须在本机代码中执行此操作并将其连接到与平台通道一起颤动,除非您有一个想法....
  • 我找到了在此应用程序中使用的音频播放器插件 (pub.dartlang.org/packages/audioplayer):youtube.com/watch?v=FE7Vtzq52xg 用于类似的范围。但我不知道这是否可以使用同一个库来完成。我真的不知道如何解码 mp3。那么原生代码和使用平台通道连接到 Flutter 是什么意思?
  • 嗨。您找到获取波形的解决方案了吗?

标签: android audio flutter


【解决方案1】:

您似乎正在研究从音频生成波形图。到目前为止你有没有尝试过?

这里没有简短的答案。您可以从flutter_ffmpeggenerate waveform data from audio 开始探索。波形数据的格式由您决定。获得数据后,您可以使用 CustomPaint 在 Flutter 中生成波形图。您可以在此blog post 上查看示例。示例中使用的波形数据为 JSON。

【讨论】:

    【解决方案2】:

    我正在寻找一种方法来收听麦克风并使用颤振进行一些音频分析,我在这里找到了一些可能对您有所帮助的方法:

    是一个两篇文章的序列,分步解释使用 Flutter 绘制波形

    生成波形数据 - 音频表示: https://matt.aimonetti.net/posts/2019-06-generating-waveform-data-audio-representation/

    在 Flutter 中绘制波形:https://matt.aimonetti.net/posts/2019-07-drawing-waveforms-in-flutter/

    希望对你有帮助

    【讨论】:

    • 是否实现了听麦克风和画波功能?
    猜你喜欢
    • 2016-12-09
    • 2017-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 2011-11-16
    相关资源
    最近更新 更多