Skip to content

Instantly share code, notes, and snippets.

@hyuki

hyuki/talks.rb Secret

Created October 6, 2021 13:20
Show Gist options
  • Save hyuki/e14c4340b4695be26015b72a89c02271 to your computer and use it in GitHub Desktop.
Save hyuki/e14c4340b4695be26015b72a89c02271 to your computer and use it in GitHub Desktop.
talks.rb - Azure Speech CLIを使って話者二人の会話を作るRubyスクリプト
#! /usr/bin/ruby
require 'wavefile'
include WaveFile
VOICE = [
"ja-JP-NanamiNeural",
"ja-JP-KeitaNeural",
]
TSV = "_talks.tsv"
open(TSV, "w") do |f|
f.puts "voice\taudio.output\ttext"
DATA.each_with_index do |line, index|
f.puts "#{VOICE[index % 2]}\t#{sprintf("%03d", index)}.wav\t#{line}"
end
end
system("sudo docker run -it -v /YOUR/WORKING/DIR/:/data --rm msftspeech/spx synthesize --foreach in #{TSV}")
Writer.new("output.wav", Format.new(:mono, :pcm_16, 16000)) do |writer|
Dir.glob("00*.wav").sort.each do |filename|
Reader.new(filename).each_buffer do |buffer|
writer.write(buffer)
end
end
end
__END__
これはファイルから読み込んでいます。
TSVファイルを利用して複数のファイルを作っています。
話者も切り換えられるといいですね。
切り換えられるみたいですよ。
@hyuki
Copy link
Author

hyuki commented Oct 6, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment