Skip to content

Commit

Permalink
feat. update to support Ubuntu 22.04 (requirements.txt
Browse files Browse the repository at this point in the history
feat. update install script
feat. add text2speech sample src/GenVoice.py
bugfix. fix openai lib issue
  • Loading branch information
hyili committed Jul 24, 2023
1 parent 407103a commit d4e2a9c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ simple-websocket==0.9.0
six==1.16.0
sniffio==1.3.0
tokenizers==0.13.2
torch==1.10.1
torch==1.11.0
tqdm==4.65.0
transformers==4.26.1
typing-extensions==4.5.0
Expand Down
2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

pip3 install -r requirements.txt
sudo apt install portaudio19-dev
pip3 install -r requirements.txt
mkdir -p record private audio markdown
12 changes: 12 additions & 0 deletions src/GT2S.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,17 @@ def text2speech(self, msg, speed=1):
#self.gt2s_obj.save(self.save_path+self.filename)
#os.system("play {0} speed {1} >> /dev/null 2>&1".format(self.save_path+self.filename, speed))

def text2speechfile(self, msg, filename, speed=1):
msg = self.remove_codeblock(msg)
self.gtrans_obj = self.gtranslator.detect(msg)
self.gt2s_obj = GTTS(text=msg, lang=self.gtrans_obj.lang, slow=False)
mem = BytesIO()
self.gt2s_obj.write_to_fp(mem)
mem.seek(0)
s = AudioSegment.from_mp3(mem)
news = self.set_speed(s, speed)
play(news)
news.export(self.save_path+filename, format="mp3")

def __del__(self):
pass
17 changes: 17 additions & 0 deletions src/GenVoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3

import sys
from GT2S import GT2S

gt2s = GT2S(save_path="./")
counter = 1

print("Using \"quit\" or ctrl+c to exit!")
print("Input: ",end='', flush=True)
for line in sys.stdin:
if line.rstrip() == "quit":
break
elif len(line.rstrip()) > 0:
gt2s.text2speechfile(line.rstrip(), str(counter)+".mp3", speed=1.2)
counter += 1
print("Input: ",end='', flush=True)
2 changes: 1 addition & 1 deletion src/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import ChatGPT

bot = ChatGPT.ChatGPT("You are an smart assistant. and your response should be as short as possible.", speech=True)
bot = ChatGPT.ChatGPT(system_msg="", speech=True, rules_msg="You are an smart assistant. and your response should be as short as possible.")

print("Using \"quit\" or ctrl+c to exit!")
print("Input: ",end='', flush=True)
Expand Down

0 comments on commit d4e2a9c

Please sign in to comment.