Giter VIP home page Giter VIP logo

bokuno-narrator's Introduction

BOKUNO-NARRATOR ぼくのナレーターさん

_data/narrae.txtを行ごとに読み上げ、字幕ファイルを作ります。
バックグラウンドでOBSなどで録画したファイルが有れば下記コマンドで字幕ファイルと統合できます。

$ ffmpeg -i input.mp4 -vf "ass=字幕.ass" -c:v h264_nvenc output.mp4

Usage

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"path/filepath"
	"strings"
	"time"

	"bokuno-narrator/subtitle"

	"github.com/go-numb/go-bouyomichan"
)

const (
	// 改行してセリフを書き込む
	narratefile = "./_data/narrate.txt"
)

var (
	// 指定のワードが含まれたコメント(投稿)を除く
	EXCLUDE = []string{}
	// 置き換える
	REPLACEWORDS = []string{"死", "殺"}

    // 掛け合いにする
    isDialogue = true
)

func init() {
	f, _ := os.Open("./_data/excludes.txt")
	defer f.Close()

	s := bufio.NewScanner(f)
	for s.Scan() {
		EXCLUDE = append(EXCLUDE, s.Text())
	}
	if err := s.Err(); err != nil {
		log.Fatal(err)
	}

	fmt.Println(EXCLUDE)
}

func main() {
	bouyomi := bouyomichan.New("localhost:50001")
	bouyomi.Voice = bouyomichan.VoiceNeutral
	bouyomi.Tone = 110

	words := Read(narratefile)

	content := subtitle.New("market maker bot")
	content.PageID = "mm"

	var (
		start = time.Now()
		in    int64
	)
	for i := 0; i < len(words); i++ {
		if isDialogue {
            if i%2 == 0 {
                bouyomi.Voice = bouyomichan.VoiceDefault
                bouyomi.Tone = 105
            } else {
                bouyomi.Voice = bouyomichan.VoiceNeutral
                bouyomi.Tone = 110
            }
        }

		in = time.Now().UnixMilli() - start.UnixMilli()
		bouyomi.Speaking(words[i])
		for {
			if !bouyomi.IsNowPlayng() {
				break
			}
		}
		time.Sleep(200 * time.Millisecond)
		log.Println("[INFO] end one sentence")

		content.Posts = append(content.Posts, subtitle.Post{
			PageID: content.PageID,
			UID:    i,
			Text:   words[i],
			Start:  in,
			End:    time.Now().UnixMilli() - start.UnixMilli(),
		})
	}

	content.ToAss(false, filepath.Clean(narratefile))
}

func Read(filename string) (words []string) {
	f, _ := os.Open(filepath.Clean(narratefile))
	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		w := scanner.Text()
		for j := 0; j < len(EXCLUDE); j++ {
			if strings.Contains(w, EXCLUDE[j]) {
				continue
			}
		}
		for j := 0; j < len(REPLACEWORDS); j++ {
			w = strings.ReplaceAll(w, REPLACEWORDS[j], "◯")
		}
		words = append(words, w)
	}

	if err := scanner.Err(); err != nil {
		log.Fatal(err)
	}

	return words
}

bokuno-narrator's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.