gpt4 book ai didi

ios - xamarin iOS : How to show the audio amplitude of the voice when recording

转载 作者:行者123 更新时间:2023-12-02 23:38:48 24 4
gpt4 key购买 nike

在 Android 上,我发现可以定期使用 getMaxAmplitude 来显示录音的幅度。 iOS有同样的功能吗?我想在从麦克风录音时显示输入语音音量表。

最佳答案

假设您使用 AVAudioRecorder您可以启用计量并读取每个音频 channel 的平均和峰值音量(以分贝为单位)。

每秒采样 10 次麦克风:

# AVAudioSettings setup ...
~~~
avAudioRecorder = AVAudioRecorder.Create(this.audioFilePath, new AudioSettings(settings), out error);
avAudioRecorder.MeteringEnabled = true;

var peakPower = 0.0;
var averagePower = 0.0;
// Note: No await, run the following Task synchronously!
Task.Run(async() => // Personally I would create my own Thread, but this works for a quick example
{
while (true) // Do not create object/release objects or subtasks in this loop, it will cause poor performance due to GC.
{
if (!avAudioRecorder.Recording)
return;
avAudioRecorder.UpdateMeters();
peakPower = avAudioRecorder.PeakPower(0);
averagePower = avAudioRecorder.AveragePower(0);
Console.WriteLine($"{averagePower}:{peakPower}");
Thread.Sleep(100);
}
});

输出:
2017-01-14 19:26:16.271 Sound[33399:19078946] -52.9222717285156:-48.1419296264648
2017-01-14 19:26:17.271 Sound[33399:19078946] -53.7662239074707:-45.7719497680664
2017-01-14 19:26:18.274 Sound[33399:19078946] -49.105827331543:-43.4426803588867
2017-01-14 19:26:19.275 Sound[33399:19078946] -9.97611618041992:4.59128427505493
2017-01-14 19:26:20.276 Sound[33399:19078946] -37.2582626342773:5.28962087631226
2017-01-14 19:26:21.276 Sound[33399:19078946] -24.4357891082764:4.00279855728149
2017-01-14 19:26:22.277 Sound[33399:19078946] -11.7632217407227:4.34794473648071
2017-01-14 19:26:23.278 Sound[33399:19078946] -32.4504356384277:5.66976404190063
2017-01-14 19:26:24.279 Sound[33399:19078946] -18.5233268737793:0.0205818619579077
2017-01-14 19:26:25.280 Sound[33399:19078946] -28.790828704834:-5.83084678649902

引用: https://developer.apple.com/reference/avfoundation/avaudiorecorder

in decibels, for the sound being recorded. A return value of 0 dB indicates full scale, or maximum power; a return value of -160 dB indicates minimum power (that is, near silence).

If the signal provided to the audio recorder exceeds ±full scale, then the return value may exceed 0 (that is, it may enter the positive range).

关于ios - xamarin iOS : How to show the audio amplitude of the voice when recording,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41655095/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com