csdcorp / speech_to_text

A Flutter plugin that exposes device specific text to speech recognition capability.
BSD 3-Clause "New" or "Revised" License
372 stars 231 forks source link

Speech-to-Text Fails on Simulator After Connecting External Audio Interface on macOS M3 Pro #549

Open CristianAragon opened 1 month ago

CristianAragon commented 1 month ago

After connecting an external audio interface, the speech-to-text functionality stopped working in the simulator.

Package: speech_to_text: ^7.0.0-beta.1

Environtment:

MacBook with an M3 Pro chip.

Flutter 3.25.0-1.0.pre.54 • channel master • https://github.com/flutter/flutter.git
Framework • revision d0d23300e6 (2 hours ago) • 2024-08-20 19:16:07 -0400
Engine • revision 3d18f65c37
Tools • Dart 3.6.0 (build 3.6.0-162.0.dev) • DevTools 2.39.0-dev.15

Tests:

I'm unsure if this is a bug in the library or if the audio interface has altered some settings.

I’ve tried various solutions but haven’t been able to fix it:

await session.configure(AudioSessionConfiguration(
  avAudioSessionCategory: AVAudioSessionCategory.playAndRecord,
  avAudioSessionCategoryOptions: AVAudioSessionCategoryOptions.defaultToSpeaker,
  avAudioSessionMode: AVAudioSessionMode.spokenAudio,
  avAudioSessionPreferredSampleRate: 44100, // Added this line
));

Relevant Console Logs:

When the interface is connected (speech works):

default 13:48:39.017544-0300    Runner         AggregateDevice.mm:983   PrimarySessionActiveWithInputEnabled 0 -> 1
default 13:48:40.630472-0300    Runner             AQMEIO_HAL.cpp:2475  aqmeio@0x138808218, device 136 (iOSSimulatorAudioDevice-4187-5), AudioDeviceStart (err 0)
default 13:48:40.642229-0300    Runner             AQMEIO_HAL.cpp:527   iOSSimulatorAudioDevice-4187-5 (136): IO started 1 (err 0), was running 1, running count 1
default 13:48:41.669002-0300    Runner  flutter: [speech recognition service] status: listening

When the interface is not connected (speech fails):

error   13:28:10.850234-0300    Runner      AVAudioSession_iOS.mm:1192  AudioSessionGetProperty (temp_kMXSessionProperty_HasEchoCancelledInput) failed with error: -50
error   13:28:10.938749-0300    Runner             AVAEInternal.h:76    required condition is false: [AVAudioIONodeImpl.mm:1281:SetOutputFormat: (format.sampleRate == hwFormat.sampleRate)]
error   13:28:10.939117-0300    Runner  Error starting listen: The operation couldn't be completed. (Try error 1.)
default 13:28:10.939250-0300    Runner  AVAudioSessionImpl_Simulator.mm:136   Set volume on device 72 to 0.60
default 13:28:10.939294-0300    Runner         AggregateDevice.mm:983   PrimarySessionActiveWithInputEnabled 1 -> 0

I also tried running the example, but I encountered the same results:

image

I'm continuing to debug this issue, but I wanted to report it here in case someone else is experiencing the same problem.

Thanks in advance for any assistance.