回答編集履歴
2
実例の追記
test
CHANGED
@@ -17,4 +17,50 @@
|
|
17
17
|
}
|
18
18
|
```
|
19
19
|
|
20
|
+
## 実例追記
|
20
21
|
|
22
|
+
このようにまとめてレスポンスを返すように組むと、chunkedエンコーディングでレスポンスが返る事を確認できましたし、ノイズもありませんでした。
|
23
|
+
|
24
|
+
https://go.dev/play/p/qkKllEZQH2r
|
25
|
+
```go
|
26
|
+
package main
|
27
|
+
|
28
|
+
import (
|
29
|
+
"fmt"
|
30
|
+
"io"
|
31
|
+
"log"
|
32
|
+
"net/http"
|
33
|
+
"os"
|
34
|
+
|
35
|
+
"github.com/zaf/resample"
|
36
|
+
)
|
37
|
+
|
38
|
+
func index(w http.ResponseWriter, r *http.Request) {
|
39
|
+
fmt.Fprintln(w, "index")
|
40
|
+
}
|
41
|
+
|
42
|
+
func handler(w http.ResponseWriter, r *http.Request) {
|
43
|
+
input, err := os.Open("OUTPUT.raw")
|
44
|
+
if err != nil {
|
45
|
+
log.Print(err)
|
46
|
+
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
47
|
+
return
|
48
|
+
}
|
49
|
+
res, err := resample.New(w, float64(48000), float64(8000), 1, resample.I16, resample.HighQ)
|
50
|
+
if err != nil {
|
51
|
+
log.Print(err)
|
52
|
+
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
53
|
+
return
|
54
|
+
}
|
55
|
+
io.Copy(res, input)
|
56
|
+
}
|
57
|
+
|
58
|
+
func main() {
|
59
|
+
http.HandleFunc("/", index)
|
60
|
+
http.HandleFunc("/audio", handler)
|
61
|
+
if err := http.ListenAndServe(":8080", nil); err != nil {
|
62
|
+
log.Fatal(err)
|
63
|
+
}
|
64
|
+
}
|
65
|
+
```
|
66
|
+
|
1
追記
test
CHANGED
@@ -1,2 +1,20 @@
|
|
1
1
|
リサンプルですがその組み合わせ限定ですが6個ずつの平均値に変換するという手もあります。
|
2
2
|
(もちろん、6個未満のデータは次のデータが読めるところまで持ち越すという処理は必要です)
|
3
|
+
|
4
|
+
## 追記
|
5
|
+
|
6
|
+
区切り方を質問されていますが、はっきり言って(音声処理のプロでも苦労するほど)難関過ぎて区切るのはお勧めしません。
|
7
|
+
一通りの処理が終わるまでストリーミングを「**区切らない**」が正解です。
|
8
|
+
|
9
|
+
Resamplerも入力も出力も一度インスタンスを作ったら、一通りのデータ処理が終わるまで使いまわしましょう。
|
10
|
+
|
11
|
+
また、chunkedエンコードのことを言っているのならGoのサーバーはContent-Lengthを付けないようにしつつレスポンス全体の処理を繰り返しResponseWriterに書き込むことで自動的にchunkedエンコードでレスポンスを組み立ててくれます。
|
12
|
+
|
13
|
+
あと以下のコードが部分バッファ書き出しごとにあるとよいでしょう。
|
14
|
+
```go
|
15
|
+
if flusher, ok := w.(http.Flusher); ok {
|
16
|
+
flusher.Flush()
|
17
|
+
}
|
18
|
+
```
|
19
|
+
|
20
|
+
|