浏览代码

update packages

subDesTagesMitExtraKaese 2 年之前
父节点
当前提交
d413f0e33f
共有 4 个文件被更改,包括 115 次插入96 次删除
  1. 1 0
      .gitignore
  2. 34 0
      audio.py
  3. 80 96
      beleg.ipynb
  4. 二进制
      beleg.pdf

+ 1 - 0
.gitignore

@@ -3,3 +3,4 @@
 .ipynb_checkpoints/
 
 .vscode/
+__pycache__/

+ 34 - 0
audio.py

@@ -0,0 +1,34 @@
+import IPython.display
+import numpy as np
+import json
+
+def Audio(audio: np.ndarray, rate: int):
+    """
+    Use instead of IPython.display.Audio as a workaround for VS Code.
+    `audio` is an array with shape (channels, samples) or just (samples,) for mono.
+    """
+
+    if np.ndim(audio) == 1:
+        channels = [audio.tolist()]
+    else:
+        channels = audio.tolist()
+
+    return IPython.display.HTML("""
+        <script>
+            if (!window.audioContext) {
+                window.audioContext = new AudioContext();
+                window.playAudio = function(audioChannels, sr) {
+                    const buffer = audioContext.createBuffer(audioChannels.length, audioChannels[0].length, sr);
+                    for (let [channel, data] of audioChannels.entries()) {
+                        buffer.copyToChannel(Float32Array.from(data), channel);
+                    }
+            
+                    const source = audioContext.createBufferSource();
+                    source.buffer = buffer;
+                    source.connect(audioContext.destination);
+                    source.start();
+                }
+            }
+        </script>
+        <button onclick="playAudio(%s, %s)" style="padding: 10px">Play</button>
+    """ % (json.dumps(channels), rate))

文件差异内容过多而无法显示
+ 80 - 96
beleg.ipynb


二进制
beleg.pdf