3

我正在使用 Flutter 构建一个应用程序,它允许我录制音频,然后再播放。我正在使用audio_recorder 0.4.0用于录制音频的包和stereo 1.0.0用于播放音频的包。

当我使用 iOS 模拟器录制时,一切正常。但是当我在物理设备(iPhone 6 Plus)上运行时,我总是在录制会话结束时得到一个 28 字节的文件——基本上只是 m4a 文件的标题。

我已经将此归结为两个库之间的某种干扰。如果我使用附带的示例应用程序,我可以在物理设备上进行录制audio_recorder 0.4.0。但我所要做的就是将这一行添加stereo: 1.0.0到同一个示例项目的 pubspec.yml 中的依赖项中,然后我突然开始在录制会话结束时在物理设备上获取 28 字节文件,而不是正常大小的 m4a 文件。

我有一个两部分的问题:

  1. stereo图书馆可能会造成什么样的干扰,导致图书馆出现这种故障audio_recorder?我怀疑信道干扰,但我试图隔离它并没有产生任何结果。

  2. 我怎样才能找到造成这种情况的原因?

我检查了两个会话的控制台输出。当它失败时,我在尝试开始录制后立即在控制台输出中看到其中的几 (8) 行:

mediaserverd    1111: AudioConverterNew returned -50

其他人建议当没有可用的麦克风时会发生此错误。

我还看到了输出之间的这种可疑差异。录音中断时:

default 11:36:57.098825 -0700   mediaserverd    4414: { "action":"set_play_state", "session":{"ID":"0x3315820","PID":14591,"name":"Runner"}, "details":"entry" }
default 11:36:57.100484 -0700   mediaserverd    -CMSessionMgr- cmsSetIsPlaying: CMSession: 'sid:0x3315820, Runner(14591), 'prim'' with [MediaPlayback/Default] [NonMixable] [System Audio] starting playing.
default 11:36:57.104699 -0700   mediaserverd    CAReportingClient.mm:328:-[CAReportingClient sendMessage:category:type:reporters:]: message {
    Volume = "0.75";
    VolumeCategory = "Audio/Video";
    VolumeOperationProcess = "com.monkela.audioRecordSample";
    VolumeOperationTime = 576708;
    VolumePlayingState = 1;
}: (
    857014545
)
default 11:36:57.105879 -0700   mediaserverd    -CMVAEndptMgr- vaemSetDeviceVolume: CMSession: Setting cmsvolume = 0.750 for device ID: VirtualAudioDevice_Default
default 11:36:57.107295 -0700   mediaserverd    VirtualAudio_Device.cpp:2046:SetPropertyData: [volm/outp/0] on device [ type: vdef; id: 354; addr: 0x1014e1ba0; hidden: 0; VA strms: { o/883/0x106fc5980 }; agg dev: [ id: 872; addr: 0x106f1a460; uid: "VAD [vdef] AggDev 52"; virt strms: {  }; phys devs: { [ id: 292; addr: 0x104b0fdb0; uid: "Speaker"; streams: { i/294/0x104b11cd0, o/293/0x104b12790 } ] } ] ]: 0.750000.
default 11:36:57.108123 -0700   mediaserverd    OutputVolumeControl_HAL_Common.cpp:662:CommitVolume: Setting Volume = -14.500000 dB, Final HW Volume = 0.000000 dB, Final SW Volume = -14.500000 dB, External Volume Handler: No
default 11:36:57.109008 -0700   mediaserverd    OutputVolumeControl_HAL_Common.cpp:663:CommitVolume:     PhysicalDevice UID = "Speaker"
default 11:36:57.109721 -0700   mediaserverd    OutputVolumeControl_HAL_Common.cpp:664:CommitVolume:     Scope = 1869968496 ("outp")
default 11:36:57.110704 -0700   mediaserverd    OutputVolumeControl_HAL_Common.cpp:665:CommitVolume:     Element = 0 ("0")
default 11:36:57.112062 -0700   mediaserverd    OutputVolumeControl_HAL_Common.cpp:698:CommitVolume:     SW Volume: 0.750000 scalar
default 11:36:57.114393 -0700   mediaserverd    VirtualAudio_Device.cpp:2066:SetPropertyData: Client request to set nominal sample rate to 44100.000000 on VAD 354.
default 11:36:57.116038 -0700   assertiond  [Runner:14591] Attempting to acquire assertion for Runner:14591: <BKProcessAssertion: 0x101349110; "CMSession.14591."com.monkela.audioRecordSample"."MediaPlayback".isPlayingProcessAssertion" (audio:inf); id:…C74721DE1F95>
default 11:36:57.116572 -0700   assertiond  [Runner:14591] Add assertion: <BKProcessAssertion: 0x101349110; id: 13077-914DDDE2-35CE-4420-85ED-C74721DE1F95; name: CMSession.14591."com.monkela.audioRecordSample"."MediaPlayback".isPlayingProcessAssertion; state: active; reason: audio; duration: infs> {
    owner = <BSProcessHandle: 0x101009be0; mediaserverd:13077; valid: YES>;
    flags = preventSuspend, preventThrottleDownCPU, preventIdleSleep, preventSuspendOnSleep;
}

录制工作时:

default 11:39:19.865022 -0700   mediaserverd    2863: { "action":"activate", "session":{"ID":"0x3315826","PID":14609,"name":"Runner"}, "details":"entry" }
default 11:39:19.880637 -0700   mediaserverd    CAReportingClient.mm:328:-[CAReportingClient sendMessage:category:type:reporters:]: message {
    "active devices" = "[ { vdef, [  ], [ pspk ( 0 ) ] }, { vspd, [ pmbi ( 0 ) ], [  ] }, { vcal, [ pdln ( 0 ) ], [ puln ( 0 ) ] } ]";
    category = csav;
    "going_active" = 1;
    mode = imdf;
    "staying_active" = 0;
}: (
    857014546
)

录制中断时的输出表明我尝试开始录制实际上开始播放某些内容(即调用错误的库)。

4

1 回答 1

3

我追踪了这一点,并想出了如何通过修改stereo包来使库一起工作。事实证明,该stereo程序包正在激活一个播放音频会话application didFinishLaunchingWithOptions。基本上这些行:

AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:&error];
[session setActive:YES error:&error];

我分叉了stereo包并更改了代码以仅在实际需要时才激活播放会话。神奇地我的记录功能开始工作了。

我不确定为什么它曾经在模拟器中工作过。不知何故,模拟器必须能够同时进行回放和录制会话。

更新:stereo包的作者接受了我的拉取请求,所以只要你有包的 1.0.1 版本,你应该能够避免这个干扰问题。

于 2018-06-07T05:28:54.000 回答