I had google-home perform the beauty conference

Motivation for creation

You can make google-home speak with python, but it's not fun to just say one word, so I wanted to make it speak like a conversation

What is a beauty meeting?

See [NEOGEO Meeting Room] in here

Source

talk.py


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time
import datetime
import pychromecast
from gtts import gTTS
from mutagen.mp3 import MP3

#Google by IP address-Specify home
googleHome = pychromecast.Chromecast('192.168.0.xx')

if not googleHome.is_idle:
    googleHome.quit_app()
    time.sleep(5)

f = open('./script.txt', 'r') #Prepare a text that describes the conversation
line = f.readline()

while line:
  #Speak line by line
  print(line.strip())

  savefile = "voice-%s.mp3" % datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
  savepath = "/tts/%s" % savefile

  try:
    #Convert to voice data with google speech to text and save
    tts = gTTS(text=line.strip(), lang='ja')
    tts.save(savepath)
  except:
    continue
  finally:
    line = f.readline()

  #Get mp3 file information
  audio = MP3(savepath)

  #The above save path is published as a place accessible from the web
  mp3url = "https://(domainname)/tts/%s" % savefile;

  #Let google home talk mp3
  googleHome.wait()
  googleHome.media_controller.play_media(mp3url, 'audio/mp3')
  googleHome.media_controller.block_until_active()

  #If the next conversation starts while you are talking, it will stop halfway, so
  #Wait for the number of seconds of conversation data
  time.sleep(audio.info.length)

f.close()

sample script.txt

Hi! Fatal Fury's beautiful character, ~
I'll do it even if I don't bother to explain it ~
Beautiful character of Samurai Spirits, Tachibana ~

command

docker run -v /script:/data -v /tts/:/tts toru2220/google-home-python python talk.py

Actual operation

Recommended Posts

I had google-home perform the beauty conference
I counted the grains