]> Sergey Matveev's repositories - go-opus.git/commitdiff
README: Example for file & stream handling
authorHraban Luyat <hraban@0brg.net>
Fri, 19 May 2017 21:39:16 +0000 (22:39 +0100)
committerHraban Luyat <hraban@0brg.net>
Fri, 19 May 2017 21:41:53 +0000 (22:41 +0100)
README.md

index d81e148f70a039f30a545e14c69457d6c39a96ee..40c396251c56cb89f7dfff6192431f430104803e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ xiph.org opus libs:
 
 * encoders
 * decoders
-* stream handlers
+* files & streams
 
 ### Import
 
@@ -114,6 +114,33 @@ To decode a .opus file (or .ogg with Opus data), or to decode a "Opus stream"
 (which is a Ogg stream with Opus data), use the `Stream` interface. It wraps an
 io.Reader providing the raw stream bytes and returns the decoded Opus data.
 
+A crude example for reading from a .opus file:
+
+```go
+f, err := os.Open(fname)
+if err != nil {
+    ...
+}
+s, err := opus.NewStream(f)
+if err != nil {
+    ...
+}
+defer s.Close()
+buf := make([]byte, 16384)
+for {
+    n, err = s.Read(buf)
+    if err == io.EOF {
+        break
+    } else if err != nil {
+        ...
+    }
+    pcm := buf[:n*channels]
+
+    // send pcm to audio device here, or write to a .wav file
+
+}
+```
+
 See https://godoc.org/gopkg.in/hraban/opus.v2#Stream for further info.
 
 ### API Docs