0

I have a string named TextInput that contains a simple input message from the user and I am trying to experiment with getting it to be read aloud with the mimic3 tts engine. I need it to play without me having to type it into the terminal myself. Here is what I've got:

import os
TextInput = input("Text:  ")
os.system('mimic3 --interactive')

I need something that will take TextInput, type it in the terminal, and then run it

I am running this on a raspberry pi 4b 8gb with Raspberry Pi OS 64 bit installed

I have tried using the pyautogui module, but it didn't run the terminal afterwards

DrDark
  • 1
  • 1

2 Answers2

0

os.system will block until the command finishes ... try subprocess instead

proc=subprocess.Popen('mimic3 --interactive',stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
time.sleep(5) # give it a bit to start up
proc.stdin.write("hello\n")

I would expect to work... without trying it...

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • when I tried that I got this error: Traceback (most recent call last): File "/home/the-doctor/Python/test2.py", line 2, in proc=subprocess.Popen('mimic3 --interactive',stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderror=subprocess.PIPE) TypeError: __init__() got an unexpected keyword argument 'stderror' – DrDark Jun 15 '23 at 15:56
  • 1
    @DrDark, maybe try `stderr=subprocess.PIPE` instead of `stderror=subprocess.PIPE`. – l'L'l Jun 16 '23 at 02:12
  • thanks for the correction :) fixed now – Joran Beasley Jun 16 '23 at 18:13
-1

I got it to work by doing:

import time
import subprocess

proc = subprocess.Popen(['mimic3', '--interactive'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, text=True)
proc.stdin.write('systems online\n')
proc.stdin.flush()
time.sleep(10)

while True:
    text = input("text: ")
    proc.stdin.write(text + '\n')
    proc.stdin.flush()

I found the what I needed here

DrDark
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 16 '23 at 15:44