err := beeep.Notify("title", "Some text", "hiking.png")
beeep.Notify
вам надо будет сохранить вшитую картинку во временный файл и передать в beeep.Notify
путь к нему. package main
import (
"embed"
_ "image/jpeg"
"log"
_ "embed"
"github.com/gen2brain/beeep"
rand2 "math/rand"
"time"
)
//go:embed img.jpg
var f embed.FS
func main() {
//err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration)
//if err != nil {
// panic(err)
//}
orders := [3]string{"Text1", "Text2", "Text3"}
img, err := f.ReadFile("img.jpg")
if err != nil {
log.Fatalln(err)
}
var counter int
for range time.Tick(time.Second * 1) {
rand := rand2.Intn(3)
err := beeep.Notify("Батя", orders[rand], string(img))
if err != nil {
panic(err)
}
counter += 1
if counter > 10 {
panic(counter)
}
}
//err := beeep.Alert("Title", "Message body", "assets/warning.png")
//if err != nil {
// panic(err)
//}
}
file, err := ioutil.TempFile("dir", "prefix")
if err != nil {
log.Fatal(err)
}
defer os.Remove(file.Name())
file, err := ioutil.TempFile(".", "img.jpg")
if err != nil {
log.Fatal(err)
}
if _, err := file.Write(img); err != nil {
log.Fatal(err)
}
package main
import (
"bytes"
_ "embed"
_ "image/jpeg"
"io"
"log"
rand2 "math/rand"
"os"
"time"
"github.com/gen2brain/beeep"
)
//go:embed img.jpg
var imgBody []byte
func main() {
...
f, err := os.CreateTemp("", "")
if err != nil {
log.Fatalln(err)
}
defer func() {
_ = os.Remove(f.Name())
}()
_, err = io.Copy(f, bytes.NewReader(imgBody))
if err != nil {
log.Fatalln(err)
}
err = f.Close()
if err != nil {
log.Fatalln(err)
}
...
for range time.Tick(time.Second * 1) {
...
err := beeep.Notify("Батя", orders[rand], f.Name())
...
}
}
os.CreateTemp("", "")
.jpg
. package main
import (
"context"
"io"
"os"
"github.com/hajimehoshi/go-mp3"
"github.com/hajimehoshi/oto"
)
func playMP3(mp3Path string) error {
f, err := os.Open(mp3Path)
if err != nil {
return err
}
defer func() { _ = f.Close() }()
d, err := mp3.NewDecoder(f)
if err != nil {
return err
}
c, err := oto.NewContext(d.SampleRate(), 2, 2, 8192)
if err != nil {
return err
}
defer func() { _ = c.Close() }()
p := c.NewPlayer()
defer func() { _ = p.Close() }()
if _, err := io.Copy(p, d); err != nil {
return err
}
return nil
}
go get https://github.com/hajimehoshi/go-mp3/
PS C:\Users\User\Desktop\go_game> go get github.com/hajimehoshi/go-mp3
go: downloading github.com/hajimehoshi/go-mp3 v0.3.4
go: github.com/hajimehoshi/go-mp3@v0.3.4: reading https://proxy.golang.org/github.com/hajimehoshi/go...: 403 Forbidden
2022/12/20 14:53:45 mp3: free bitrate format is not supported. Header word is 0xfffc0081 at position 61
exit status 1
//go:embed p.mp3
var p []byte
func playMP3() error {
//f, err := os.Open(mp3Path)
//if err != nil {
// return err
//}
//defer func() { _ = f.Close() }()
f, err := os.CreateTemp("", "")
defer func() {
_ = os.Remove(f.Name())
}()
d, err := mp3.NewDecoder(f)
if err != nil {
return err
}
c, err := oto.NewContext(d.SampleRate(), 2, 2, 8192)
if err != nil {
return err
}
defer func() { _ = c.Close() }()
p := c.NewPlayer()
defer func() { _ = p.Close() }()
if _, err := io.Copy(p, io.Reader(d)); err != nil {
return err
}
return nil
}