pxt-microbit 5.1.23 → 5.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/built/sim.d.ts CHANGED
@@ -576,8 +576,9 @@ declare namespace pxsim.record {
576
576
  function audioIsPlaying(): boolean;
577
577
  function audioIsRecording(): boolean;
578
578
  function audioIsStopped(): boolean;
579
- function setSampleRate(rate: number): void;
580
- function getSampleRate(): number;
579
+ function setInputSampleRate(sampleRate: number): void;
580
+ function setOutputSampleRate(sampleRate: number): void;
581
+ function setBothSamples(sampleRate: number): void;
581
582
  }
582
583
  declare namespace pxsim {
583
584
  class SerialState {
package/built/sim.js CHANGED
@@ -2285,22 +2285,59 @@ var pxsim;
2285
2285
  (function (pxsim) {
2286
2286
  var record;
2287
2287
  (function (record_1) {
2288
+ let stream;
2289
+ let recorder;
2290
+ let chunks;
2291
+ let audioURL;
2292
+ let recording;
2293
+ let audioPlaying = false;
2288
2294
  async function record() {
2289
2295
  //request permission is asynchronous
2290
2296
  let b = pxsim.board();
2291
2297
  if (!b.recordingState.currentlyRecording) {
2292
2298
  b.recordingState.currentlyRecording = true;
2293
2299
  pxsim.runtime.queueDisplayUpdate();
2300
+ if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
2301
+ try {
2302
+ stream = await navigator.mediaDevices.getUserMedia({ video: false, audio: true });
2303
+ recorder = new MediaRecorder(stream);
2304
+ recorder.start();
2305
+ setTimeout(() => {
2306
+ recorder.stop();
2307
+ pxsim.runtime.queueDisplayUpdate();
2308
+ }, 4000);
2309
+ recorder.ondataavailable = (e) => {
2310
+ chunks.push(e.data);
2311
+ };
2312
+ recorder.onstop = () => {
2313
+ const blob = new Blob(chunks, { type: "audio/ogg; codecs=opus" });
2314
+ audioURL = window.URL.createObjectURL(blob);
2315
+ recording = new Audio(audioURL);
2316
+ b.recordingState.currentlyRecording = false;
2317
+ erase();
2318
+ };
2319
+ }
2320
+ catch (error) {
2321
+ console.log("An error occurred, could not get microphone access");
2322
+ }
2323
+ }
2324
+ else {
2325
+ console.log("getUserMedia not supported on your browser!");
2326
+ }
2294
2327
  }
2295
2328
  }
2296
2329
  record_1.record = record;
2297
2330
  function play() {
2331
+ if (recording) {
2332
+ recording.play();
2333
+ }
2298
2334
  }
2299
2335
  record_1.play = play;
2300
2336
  function stop() {
2301
2337
  }
2302
2338
  record_1.stop = stop;
2303
2339
  function erase() {
2340
+ chunks = [];
2304
2341
  }
2305
2342
  record_1.erase = erase;
2306
2343
  function setMicrophoneGain(gain) {
@@ -2311,24 +2348,34 @@ var pxsim;
2311
2348
  }
2312
2349
  record_1.audioDuration = audioDuration;
2313
2350
  function audioIsPlaying() {
2314
- return false;
2351
+ if (recording) {
2352
+ recording.addEventListener("playing", () => {
2353
+ audioPlaying = true;
2354
+ }, { once: true });
2355
+ recording.addEventListener("ended", () => {
2356
+ audioPlaying = false;
2357
+ }, { once: true });
2358
+ }
2359
+ return audioPlaying;
2315
2360
  }
2316
2361
  record_1.audioIsPlaying = audioIsPlaying;
2317
2362
  function audioIsRecording() {
2318
- return false;
2363
+ return recorder ? recorder.state == "recording" : false;
2319
2364
  }
2320
2365
  record_1.audioIsRecording = audioIsRecording;
2321
2366
  function audioIsStopped() {
2322
- return false;
2367
+ return recorder ? !audioPlaying && recorder.state == "inactive" : true;
2323
2368
  }
2324
2369
  record_1.audioIsStopped = audioIsStopped;
2325
- function setSampleRate(rate) {
2370
+ function setInputSampleRate(sampleRate) {
2326
2371
  }
2327
- record_1.setSampleRate = setSampleRate;
2328
- function getSampleRate() {
2329
- return 0;
2372
+ record_1.setInputSampleRate = setInputSampleRate;
2373
+ function setOutputSampleRate(sampleRate) {
2374
+ }
2375
+ record_1.setOutputSampleRate = setOutputSampleRate;
2376
+ function setBothSamples(sampleRate) {
2330
2377
  }
2331
- record_1.getSampleRate = getSampleRate;
2378
+ record_1.setBothSamples = setBothSamples;
2332
2379
  })(record = pxsim.record || (pxsim.record = {}));
2333
2380
  })(pxsim || (pxsim = {}));
2334
2381
  var pxsim;
@@ -2956,7 +3003,7 @@ path.sim-board {
2956
3003
  pxsim.svg.fill(this.display, theme.display);
2957
3004
  pxsim.svg.fills(this.leds, theme.ledOn);
2958
3005
  pxsim.svg.fills(this.ledsOuter, theme.ledOff);
2959
- if (this.microphoneLed && (this.board.microphoneState.sensorUsed || this.board.recordingState.currentlyRecording)) {
3006
+ if (this.microphoneLed && this.board.microphoneState.sensorUsed) {
2960
3007
  pxsim.svg.fills([this.microphoneLed], theme.ledOn);
2961
3008
  pxsim.svg.filter(this.microphoneLed, `url(#ledglow)`);
2962
3009
  }
@@ -3073,10 +3120,19 @@ path.sim-board {
3073
3120
  }
3074
3121
  updateRecordingActive() {
3075
3122
  const b = pxsim.board();
3076
- if (!b
3077
- || !b.recordingState.currentlyRecording)
3123
+ if (!b)
3078
3124
  return;
3079
- this.updateTheme();
3125
+ let theme = this.props.theme;
3126
+ if (this.microphoneLed) {
3127
+ if (b.recordingState.currentlyRecording) {
3128
+ pxsim.svg.fills([this.microphoneLed], theme.ledOn);
3129
+ pxsim.svg.filter(this.microphoneLed, `url(#ledglow)`);
3130
+ }
3131
+ else if (!b.microphoneState.sensorUsed) {
3132
+ pxsim.svg.fills([this.microphoneLed], theme.ledOff);
3133
+ pxsim.svg.filter(this.microphoneLed, `url(#none)`);
3134
+ }
3135
+ }
3080
3136
  }
3081
3137
  updateButtonAB() {
3082
3138
  let state = this.board;