Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio is not getting recorded on calling "start" in web #340

Closed
naveenbharadwaj19 opened this issue Jun 5, 2024 · 1 comment
Closed

Comments

@naveenbharadwaj19
Copy link

naveenbharadwaj19 commented Jun 5, 2024

Package version
5.1.0

record_web version
1.1.1

Environment

  • OS: windows
  • Browser chrome
  • Target : Web

Describe the bug
I'm trying to record audio and download it to my computer. When I hit stop, the recorded audio size is always 64 bytes and the file size is 1KB, but nothing is being recorded.
image

 Future<void> startAudio({required BuildContext context}) async {
    try {
      _isRecording = true;
      notifyListeners();
      await record.start(
          const RecordConfig(
            encoder: AudioEncoder.pcm16bits,
            sampleRate: 22000,
            numChannels: 2,
            bitRate: 128000,
            autoGain: true,
            echoCancel: true,
            noiseSuppress: true
          ),
          path: "");
    } catch (e) {
      print(e);
    }
  }
  
  
   Future<void> stopRecordingAndSave() async {
    try {
      var audioData = await record.stop();
      _isRecording = false;
      notifyListeners();

      if (audioData != null) {
        print("Audio data size: ${audioData.length} bytes");

        final blob = html.Blob([audioData], 'audio/wav');
        final url = html.Url.createObjectUrlFromBlob(blob);

        final anchor = html.AnchorElement(href: url)
          ..setAttribute("download", "recording.wav")
          ..click();

        html.Url.revokeObjectUrl(url);
      } else {
        print("No audio data available.");
      }
    } catch (e) {
      print("Error stopping and saving");
    }
    notifyListeners();
  }
  
@llfbandit
Copy link
Owner

What you call audiodata is your path (blob URL in web). You can remove all your code below its initialisation.
By the way, PCM is not strictly WAV format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants