VapiAI / flutter

MIT License
5 stars 2 forks source link

Android deploy, error on calling assistant: 🆘Vapi - Failed to create client after 5 attempts. #2

Closed Voolu-main closed 2 months ago

Voolu-main commented 3 months ago

Hi @nikhilro,

I came across a problem on Android. Initially, the app worked perfectly on a physical device. However, after several builds, I’m now getting the errors listed below

I/flutter ( 7475): ⏳ 2024-04-03 10:16:47.369961: Vapi - Client creation timed out.
I/flutter ( 7475): 🆘 2024-04-03 10:16:47.370684: Vapi - Failed to create client after 5 attempts.

The project I'm testing is your sample:


import 'package:flutter/material.dart';
import 'package:vapi/Vapi.dart';

const VAPI_PUBLIC_KEY = '584fdfbd-ea94-4ed1-aa17-393e499618be';
const VAPI_ASSISTANT_ID = '8c06c088-8c85-4893-a237-5ffe565107f1';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String buttonText = 'Start Call';
  bool isLoading = false;
  bool isCallStarted = false;
  Vapi vapi = Vapi(VAPI_PUBLIC_KEY);

  _MyAppState() {
    vapi.onEvent.listen((event) {
      if (event.label == "call-start") {
        setState(() {
          buttonText = 'End Call';
          isLoading = false;
          isCallStarted = true;
        });
        print('call started');
      }
      if (event.label == "call-end") {
        setState(() {
          buttonText = 'Start Call';
          isLoading = false;
          isCallStarted = false;
        });
        print('call ended');
      }
      if (event.label == "message") {
        print(event.value);
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Voolu Vapi App Test'),
        ),
        body: Center(
          child: ElevatedButton(
            onPressed: isLoading
                ? null
                : () async {
                    setState(() {
                      buttonText = 'Loading...';
                      isLoading = true;
                    });

                    if (!isCallStarted) {
                      await vapi.start(
                        //assistantId: VAPI_ASSISTANT_ID,

                        assistant: {
                          "firstMessage": "Hello, I am an assistant.",
                          "model": {
                            "provider": "openai",
                            "model": "gpt-3.5-turbo",
                            "messages": [
                              {
                                "role": "system",
                                "content": "You are an assistant."
                              }
                            ]
                          },
                          "voice": "jennifer-playht"
                        },
                      );
                    } else {
                      await vapi.stop();
                    }
                  },
            child: Text(buttonText),
          ),
        ),
      ),
    );
  }
}

My flutter doctor -v:

[√] Flutter (Channel stable, 3.19.5, on Microsoft Windows [Version 10.0.22631.3296], locale en-GB)
    • Flutter version 3.19.5 on channel stable at C:\tools\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 300451adae (7 days ago), 2024-03-27 21:54:07 -0500
    • Engine revision e76c956498
    • Dart version 3.3.3
    • DevTools version 2.31.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc4)
    • Android SDK at C:\Users\burac\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0-rc4
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.4.4)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.4.33213.308
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2021.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[√] VS Code (version 1.87.2)
    • VS Code at C:\Users\burac\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.86.0

[√] Connected device (4 available)
    • SM A908B (mobile) • RFCMA02W5WT • android-arm64  • Android 12 (API 31)
    • Windows (desktop) • windows     • windows-x64    • Microsoft Windows [Version 10.0.22631.3296]
    • Chrome (web)      • chrome      • web-javascript • Google Chrome 123.0.6312.86
    • Edge (web)        • edge        • web-javascript • Microsoft Edge 123.0.2420.65

[√] Network resources
    • All expected network resources are available.

• No issues found!

Demo video [logs]:

https://github.com/VapiAI/flutter/assets/94541924/84598bb9-8270-47aa-871e-6ff84384dfa7

Any insight into what might be happening?

nikhilro commented 3 months ago

Nothing jumps out. Sounds like a debugging problem.

Voolu-main commented 3 months ago

Nothing jumps out. Sounds like a debugging problem.

  • Can you try reverting to old build? YES, right now
  • What's changed since then? Nothing, only UI
  • Have you tried debugging with GPT4? Can you offer more details, thanks?

Thanks for your support @nikhilro

Voolu-main commented 3 months ago

@nikhilro

I tried again, with the old clean project, the same issue :(

Screenshots: Screenshot 2024-04-03 205928 Screenshot 2024-04-03 210203

Log:

I/flutter ( 6941): 🔄 2024-04-03 21:01:47.252897: Vapi - Creating client (Attempt 5)... I/DailyCore( 6941): daily_core::soup::signalling: s0_name: calls0_target=daily_core::native::ffi::call_client::lifecycles0_file=daily-core/src/native/ffi/call_client/lifecycle.rss0_line=37s0_call_id="4"Soup send queue starting I/DailyCore( 6941): daily_core::call_manager: s0_name: calls0_target=daily_core::native::ffi::call_client::lifecycles0_file=daily-core/src/native/ffi/call_client/lifecycle.rss0_line=37s0_call_id="4"CallManager event loop starting I/DailyCore( 6941): daily_core::call_manager::events::participants::common: s0_name: calls0_target=daily_core::native::ffi::call_client::lifecycles0_file=daily-core/src/native/ffi/call_client/lifecycle.rss0_line=37s0_call_id="4"Participant joinedSendLog=falsePeerId="c28a862a-46f1-47dc-b1bc-951851319129"Terse=true I/DailyCore( 6941): daily_core::call_manager::events::subscription::common: s0_name: calls0_target=daily_core::native::ffi::call_client::lifecycles0_file=daily-core/src/native/ffi/call_client/lifecycle.rss0_line=37s0_call_id="4"Not syncing subscriptions yet as we're not ready to subscribeSendLog=false I/flutter ( 6941): ⏳ 2024-04-03 21:01:48.254628: Vapi - Client creation timed out. I/flutter ( 6941): 🆘 2024-04-03 21:01:48.255992: Vapi - Failed to create client after 5 attempts.

Voolu-main commented 3 months ago

@nikhilro I can send you the entire project, to check it.

Voolu-main commented 3 months ago

Hi @nikhilro any updates, please can you check it, we need it asap...thanks!

I debug the app using Android Studio, and I got this log:

🆘 2024-04-04 19:54:07.826912: Vapi - Failed to create Vapi Call. Error: {"message":"Invalid Key. Hot tip, you may be using the private key instead of the public key, or vice versa.","error":"Forbidden","statusCode":403}
nikhilro commented 2 months ago

Yup, that's it. Use the public key.

RonanJehnna commented 2 months ago

Hi @nikhilro, getting the same error on flutter but I am using a public key only.

I/flutter (31150): 🔄 2024-04-10 17:55:13.088052: Vapi - Requesting Mic Permission...
I/flutter (31150): 🆗 2024-04-10 17:55:13.253083: Vapi - Mic Permission Granted
I/flutter (31150): 🔄 2024-04-10 17:55:13.255974: Vapi - Preparing Call & Client...
I/flutter (31150): 🔄 2024-04-10 17:55:13.331110: Vapi - Creating client (Attempt 1)...
I/org.webrtc.Logging(31150): WebRtcAudioManager: ctor@[name=Thread-5, id=27073]
I/org.webrtc.Logging(31150): WebRtcAudioManager: Sample rate is set to 48000 Hz
D/CompatibilityChangeReporter(31150): Compat change id reported: 263076149; UID 10283; state: DISABLED
I/org.webrtc.Logging(31150): WebRtcAudioEffects: canUseAcousticEchoCanceler: true
I/org.webrtc.Logging(31150): WebRtcAudioEffects: canUseNoiseSuppressor: true
W/org.webrtc.Logging(31150): WebRtcAudioManager: AAudio support is currently disabled on all devices!
I/org.webrtc.Logging(31150): WebRtcAudioManager: Android SDK: 34, Release: 14, Brand: Nothing, Device: Spacewar, Id: UP1A.231005.007, Hardware: qcom, Manufacturer: Nothing, Model: A063, Product: Spacewar
I/AudioManager(31150): In isSpeakerphoneOn(), calling application: com.example.vapi_ai
I/AudioManager(31150): In isBluetoothScoOn(), calling application: com.example.vapi_ai
I/org.webrtc.Logging(31150): WebRtcAudioManager: Audio State: audio mode: MODE_NORMAL, has mic: true, mic muted: false, music active: false, speakerphone: false, BT SCO: false
I/org.webrtc.Logging(31150): WebRtcAudioManager: Audio State: 
I/org.webrtc.Logging(31150): WebRtcAudioManager:   fixed volume=false
I/org.webrtc.Logging(31150): WebRtcAudioManager:   STREAM_VOICE_CALL: volume=1, max=7, muted=false
I/org.webrtc.Logging(31150): WebRtcAudioManager:   STREAM_MUSIC: volume=5, max=16, muted=false
I/org.webrtc.Logging(31150): WebRtcAudioManager:   STREAM_RING: volume=16, max=16, muted=false
I/org.webrtc.Logging(31150): WebRtcAudioManager:   STREAM_ALARM: volume=14, max=16, muted=false
I/org.webrtc.Logging(31150): WebRtcAudioManager:   STREAM_NOTIFICATION: volume=10, max=16, muted=false
I/org.webrtc.Logging(31150): WebRtcAudioManager:   STREAM_SYSTEM: volume=1, max=16, muted=false
I/org.webrtc.Logging(31150): WebRtcAudioManager: Audio Devices: 
I/org.webrtc.Logging(31150): WebRtcAudioManager:   TYPE_BUILTIN_EARPIECE(out): channels=[1], encodings=[2], sample rates=[48000], id=2
I/org.webrtc.Logging(31150): WebRtcAudioManager:   TYPE_BUILTIN_SPEAKER(out): channels=[2], encodings=[2], sample rates=[48000], id=3
I/org.webrtc.Logging(31150): WebRtcAudioManager:   TYPE_BLUETOOTH_SCO(out): channels=[1], encodings=[2], sample rates=[8000, 16000], id=8150
I/org.webrtc.Logging(31150): WebRtcAudioManager:   TYPE_BLUETOOTH_A2DP(out): channels=[2], encodings=[2], sample rates=[48000], id=8158
I/org.webrtc.Logging(31150): WebRtcAudioManager:   TYPE_TELEPHONY(out): channels=[1, 2], encodings=[2], sample rates=[8000, 16000], id=13
I/org.webrtc.Logging(31150): WebRtcAudioManager:   TYPE_BUILTIN_MIC(in): channels=[1, 2], encodings=[2], sample rates=[8000, 12000, 16000, 24000, 32000, 48000, 11025, 22050, 44100], id=20
I/org.webrtc.Logging(31150): WebRtcAudioManager:   TYPE_BLUETOOTH_SCO(in): channels=[1], encodings=[2], sample rates=[8000, 16000], id=8153
I/org.webrtc.Logging(31150): WebRtcAudioManager:   TYPE_HDMI(in): channels=[2], encodings=[2], sample rates=[48000, 32000, 44100], id=31
I/org.webrtc.Logging(31150): WebRtcAudioManager:   TYPE_TELEPHONY(in): channels=[1, 2], encodings=[2], sample rates=[8000, 16000, 48000, 12000, 24000, 32000, 11025, 22050, 44100], id=21
I/org.webrtc.Logging(31150): WebRtcAudioManager:   TYPE_BUILTIN_MIC(in): channels=[1, 2], encodings=[2], sample rates=[8000, 12000, 16000, 24000, 32000, 48000, 11025, 22050, 44100], id=22
I/org.webrtc.Logging(31150): WebRtcAudioManager:   TYPE_UNKNOWN(in): channels=[2], encodings=[2], sample rates=[48000], id=33
I/org.webrtc.Logging(31150): WebRtcAudioManager:   TYPE_FM_TUNER(in): channels=[1, 2], encodings=[2], sample rates=[48000, 8000, 12000, 16000, 24000, 32000, 11025, 22050, 44100], id=23
D/OpenSLESPlayer(31150): ctor[tid=32291]
D/OpenSLESRecorder(31150): ctor[tid=32291]
D/OpenSLESPlayer(31150): AttachAudioBuffer
D/OpenSLESPlayer(31150): SetPlayoutSampleRate(48000)
D/OpenSLESPlayer(31150): SetPlayoutChannels(1)
D/OpenSLESPlayer(31150): AllocateDataBuffers
D/OpenSLESPlayer(31150): native buffer size: 192
D/OpenSLESPlayer(31150): native buffer size in ms: 4.00
D/OpenSLESRecorder(31150): AttachAudioBuffer
D/OpenSLESRecorder(31150): SetRecordingSampleRate(48000)
D/OpenSLESRecorder(31150): SetRecordingChannels(1)
D/OpenSLESRecorder(31150): AllocateDataBuffers
D/OpenSLESRecorder(31150): frames per native buffer: 192
D/OpenSLESRecorder(31150): frames per 10ms buffer: 480
D/OpenSLESRecorder(31150): bytes per native buffer: 384
D/OpenSLESRecorder(31150): native sample rate: 48000
I/org.webrtc.Logging(31150): WebRtcAudioManager: init@[name=Thread-5, id=27073]
I/org.webrtc.Logging(31150): WebRtcAudioManager: audio mode is: MODE_NORMAL
D/OpenSLESPlayer(31150): Init[tid=32291]
D/OpenSLESRecorder(31150): Init[tid=32291]
D/OpenSLESRecorder(31150): EnableBuiltInAEC(1)
E/OpenSLESRecorder(31150): Not implemented
D/OpenSLESRecorder(31150): EnableBuiltInNS(1)
E/OpenSLESRecorder(31150): Not implemented
I/example.vapi_ai(31150): Background concurrent copying GC freed 396719(20MB) AllocSpace objects, 3(60KB) LOS objects, 89% free, 2778KB/26MB, paused 3.116ms,19us total 141.194ms
W/example.vapi_ai(31150): ApkAssets: Deleting an ApkAssets object '<empty> and /data/app/~~UYR4jSMcuU7FZzq4bWlLJw==/com.google.android.tts-trjJgo9-en7YNu8NMXOngA==/base.apk' with 1 weak references
I/DailyCore(31150): daily_core::soup::signalling: s0_name: calls0_target=daily_core::native::ffi::call_client::lifecycles0_file=daily-core/src/native/ffi/call_client/lifecycle.rss0_line=37s0_call_id="0"Soup send queue starting
I/DailyCore(31150): daily_core::call_manager: s0_name: calls0_target=daily_core::native::ffi::call_client::lifecycles0_file=daily-core/src/native/ffi/call_client/lifecycle.rss0_line=37s0_call_id="0"CallManager event loop starting
I/flutter (31150): ⏳ 2024-04-10 17:55:14.355232: Vapi - Client creation timed out.

Flutter and dart version used image