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
3 stars 8 forks source link

Live transcriber is only returning metadata #7

Closed purplehaze2602 closed 5 months ago

purplehaze2602 commented 5 months ago

This is the code i am using.

 void transcription() async{
    String apiKey = '<MY API KEY>';

    Map<String, dynamic> params = {
      'model': 'nova-2-general',
      'language': 'en-US',
      'filler_words': false,
      'punctuation': true,
    };

    Deepgram deepgram = Deepgram(apiKey, baseQueryParams: params);

    final record = AudioRecorder();

// Check and request permission if needed
    if (await record.hasPermission()) {

      final audioStream = await record.startStream(const RecordConfig(
        encoder: AudioEncoder.pcm16bits,
        sampleRate: 16000,
        numChannels: 1,
      ));

      Stream<String> jsonStream = deepgram.transcribeFromLiveAudioStream(audioStream);

      jsonStream.listen((json) {
        print(json);
      });
   }
  }

I only get metadata as output: {"type":"Metadata","transaction_key":"deprecated","request_id":"746922cc-e470-4cfd-a01f-01792cb96a7f","sha256":"c9b92b2e86055b9dfb5fdcce4161185384ac32bf08107346e3631b1fea922fb2","created":"2024-05-07T18:42:11.487Z","duration":0.0,"channels":0}

ayushdatt commented 5 months ago

@tempo-riz Can you please help here? I am also facing same issue.

tempo-riz commented 5 months ago

Hey ! You must specify the encoding and sample rate in deepgram's params for streaming, I updated the docs since it wasn't obvious :

final streamParams = {
  // must specify encoding and sample_rate according to the audio stream
  'encoding': 'linear16',
  'sample_rate': 16000,
};