tempo-riz / deepgram_speech_to_text

A Deepgram client for Dart and Flutter, supporting all Speech-to-Text and Text-to-Speech features on every platform.
https://pub.dev/packages/deepgram_speech_to_text
MIT License
5 stars 9 forks source link

Connection WebSocketChannelException in flutter #17

Closed amit-iconflux closed 3 months ago

amit-iconflux commented 3 months ago

Getting error in flutter deepgram_speech_to_text: ^2.2.2

Connection to 'https://api.deepgram.com:0/v1/listen?model=aura-asteria-en&encoding=linear16&container=wav&detect_language=true&filler_words=false&punctuation=true#' was not upgraded to websocket

  late DeepgramLiveTranscriber transcriber;
Future<void> initDeepgramStt() async {
    await cubit.initDeepgram(isInit: true);

    final Stream<List<int>> micStream = await AudioRecorder().startStream(
      const RecordConfig(
        encoder: AudioEncoder.pcm16bits,
        sampleRate: 16000,
        numChannels: 1,
      ),
    );
    transcriber = cubit.deepgram.createLiveTranscriber(micStream);

    transcriber.stream.listen((DeepgramSttResult res) {
      Utility.showLog('${res.transcript}');
    });
  }

Getting error when call start method:

transcriber.start();

Flutter doctor result is following :

[✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-arm64 (Rosetta), locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] Connected device (4 available)
[✓] Network resources

Screenshot 2024-08-14 at 11 53 48 AM

tempo-riz commented 3 months ago

hey @amit-iconflux as mentioned in the readme "...was not upgraded to websocket" errors often mean that your parameters are invalid, in the url I see that its the case, you used params that belong to TTS instead of STT, correct ones look like that:

final streamParams = {
  'detect_language': false, // not supported by streaming API
  'language': 'en',
  // must specify encoding and sample_rate according to the audio stream
  'encoding': 'linear16',
  'sample_rate': 16000,
};

for STT streaming you can find valid params here : https://developers.deepgram.com/reference/listen-live