OuroborosM commited on
Commit
9ed883a
·
1 Parent(s): adce112

Add T2S func

Browse files
Files changed (2) hide show
  1. app.py +29 -2
  2. requirements.txt +2 -1
app.py CHANGED
@@ -17,6 +17,8 @@ from langchain.tools import DuckDuckGoSearchRun
17
  from langchain.utilities import WikipediaAPIWrapper
18
  from langchain.python import PythonREPL
19
  from langchain.chains import LLMMathChain
 
 
20
 
21
  import pinecone
22
  from pinecone.core.client.configuration import Configuration as OpenApiConfiguration
@@ -44,6 +46,12 @@ from langchain.document_loaders import (
44
  from langchain.text_splitter import RecursiveCharacterTextSplitter
45
  from langchain.docstore.document import Document
46
 
 
 
 
 
 
 
47
  # Custom document loaders
48
  class MyElmLoader(UnstructuredEmailLoader):
49
  """Wrapper to fallback to text/plain when default does not work"""
@@ -200,6 +208,24 @@ class DB_Search(BaseTool):
200
  def _arun(self, query: str):
201
  raise NotImplementedError("N/A")
202
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
 
204
 
205
  Wikipedia = WikipediaAPIWrapper()
@@ -249,7 +275,7 @@ math_tool = Tool(
249
  description ='Useful for when you need to answer questions about math.'
250
  )
251
 
252
- tools = [DB_Search(), duckduckgo_tool, wikipedia_tool, python_tool, math_tool]
253
 
254
  # tools = load_tools(["Vector Database Search","Wikipedia Search","Python REPL","llm-math"], llm=llm)
255
 
@@ -275,7 +301,8 @@ Vector Database Search: This is the internal database to search information firs
275
  Duckduckgo Internet Search: Useful to search information in internet when it is not available in other tools.
276
  Wikipedia Search: Useful to search a topic, country or person when there is no availble information in vector database
277
  Python REPL: Useful when you need python to answer questions. You should input python code.
278
- Calculator: Useful for when you need to answer questions about math."""
 
279
 
280
  FORMAT_INSTRUCTIONS = """Use the following format:
281
 
 
17
  from langchain.utilities import WikipediaAPIWrapper
18
  from langchain.python import PythonREPL
19
  from langchain.chains import LLMMathChain
20
+ import azure.cognitiveservices.speech as speechsdk
21
+
22
 
23
  import pinecone
24
  from pinecone.core.client.configuration import Configuration as OpenApiConfiguration
 
46
  from langchain.text_splitter import RecursiveCharacterTextSplitter
47
  from langchain.docstore.document import Document
48
 
49
+ speech_config = speechsdk.SpeechConfig(subscription=os.getenv('SPEECH_KEY'), region=os.getenv('SPEECH_REGION'))
50
+ audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)
51
+ speech_config.speech_synthesis_voice_name='en-US-JennyNeural'
52
+ global speech_synthesizer
53
+ speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
54
+
55
  # Custom document loaders
56
  class MyElmLoader(UnstructuredEmailLoader):
57
  """Wrapper to fallback to text/plain when default does not work"""
 
208
  def _arun(self, query: str):
209
  raise NotImplementedError("N/A")
210
 
211
+ def Text2Sound(text):
212
+ global speech_synthesizer
213
+ speech_synthesis_result = speech_synthesizer.speak_text_async(text).get()
214
+ if speech_synthesis_result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
215
+ print("Speech synthesized for text [{}]".format(text))
216
+ elif speech_synthesis_result.reason == speechsdk.ResultReason.Canceled:
217
+ cancellation_details = speech_synthesis_result.cancellation_details
218
+ print("Speech synthesis canceled: {}".format(cancellation_details.reason))
219
+ if cancellation_details.reason == speechsdk.CancellationReason.Error:
220
+ if cancellation_details.error_details:
221
+ print("Error details: {}".format(cancellation_details.error_details))
222
+ print("Did you set the speech resource key and region values?")
223
+
224
+ Text2Sound_tool = Tool(
225
+ name = "Text To Sound",
226
+ func = Text2Sound.run,
227
+ description = "Useful when you need to convert text into sound file."
228
+ )
229
 
230
 
231
  Wikipedia = WikipediaAPIWrapper()
 
275
  description ='Useful for when you need to answer questions about math.'
276
  )
277
 
278
+ tools = [DB_Search(), duckduckgo_tool, wikipedia_tool, python_tool, math_tool, Text2Sound_tool]
279
 
280
  # tools = load_tools(["Vector Database Search","Wikipedia Search","Python REPL","llm-math"], llm=llm)
281
 
 
301
  Duckduckgo Internet Search: Useful to search information in internet when it is not available in other tools.
302
  Wikipedia Search: Useful to search a topic, country or person when there is no availble information in vector database
303
  Python REPL: Useful when you need python to answer questions. You should input python code.
304
+ Calculator: Useful for when you need to answer questions about math.
305
+ Text To Sound: Useful when you need to convert text into sound file."""
306
 
307
  FORMAT_INSTRUCTIONS = """Use the following format:
308
 
requirements.txt CHANGED
@@ -5,4 +5,5 @@ gradio
5
  pinecone-client
6
  wikipedia
7
  duckduckgo-search
8
- tiktoken
 
 
5
  pinecone-client
6
  wikipedia
7
  duckduckgo-search
8
+ tiktoken
9
+ azure-cognitiveservices-speech