KashiwaByte commited on
Commit
94a764b
1 Parent(s): a2538e6

change tts to Azure

Browse files
Files changed (2) hide show
  1. app.py +23 -5
  2. requirements.txt +1 -1
app.py CHANGED
@@ -2,17 +2,34 @@
2
  import gradio as gr
3
  import openai, subprocess
4
  from pathlib import Path
5
- import pyttsx3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  # 换成你自己的api_key
8
- openai.api_key = "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"
9
  debatestyle = " "
10
  messages = [{"role": "system", "content": '你是一名逻辑性很强的资深辩手,你擅长通过数据论据和学理论据来反驳,你的反驳总是一阵见血,而且很有逻辑性。接下来我会提出我的观点,你需要做的就是针锋相对地反驳我'}]
11
  chat_transcript = ""
12
  def transcribe(audio):
13
  global messages
14
  global chat_transcript
15
-
16
  myfile=Path(audio)
17
  myfile=myfile.rename(myfile.with_suffix('.wav'))
18
  audio_file = open(myfile,"rb")
@@ -26,8 +43,9 @@ def transcribe(audio):
26
  # print(response)
27
  messages.append(system_message)
28
 
29
- pyttsx3.speak(system_message['content'])
30
 
 
31
 
32
  chat_transcript = ""
33
  for message in messages:
@@ -52,7 +70,7 @@ def initway(api_key,style):
52
  with gr.Blocks(css="#chatbot{height:300px} .overflow-y-auto{height:500px}") as init:
53
  with gr.Row():
54
  api_key = gr.Textbox(
55
- lines=1, placeholder="api_key Here...", label="api_key",value="")
56
  style = gr.Textbox(
57
  lines=1, placeholder="style Here...", label="辩风" ,value="你是一名逻辑性很强的资深辩手,你擅长通过数据论据和学理论据来反驳,你的反驳总是一阵见血,而且很有逻辑性。接下来我会提出我的观点,你需要做的就是针锋相对地反驳我,每次回答不超过100个字")
58
  btn = gr.Button(value="初始化")
 
2
  import gradio as gr
3
  import openai, subprocess
4
  from pathlib import Path
5
+ import os
6
+ import azure.cognitiveservices.speech as speechsdk
7
+
8
+
9
+ # Azure tts
10
+ # This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
11
+ SPEECH_REGION='eastus'
12
+ SPEECH_KEY= 'af2d4aa2348b4b73b60487c73e0eb431'
13
+
14
+ speech_config = speechsdk.SpeechConfig(subscription='af2d4aa2348b4b73b60487c73e0eb431', region='eastus')
15
+ audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)
16
+
17
+ # The language of the voice that speaks.
18
+ speech_config.speech_synthesis_voice_name=' zh-CN-XiaoxiaoNeural'
19
+
20
+ speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
21
+
22
+
23
 
24
  # 换成你自己的api_key
25
+ openai.api_key = "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"
26
  debatestyle = " "
27
  messages = [{"role": "system", "content": '你是一名逻辑性很强的资深辩手,你擅长通过数据论据和学理论据来反驳,你的反驳总是一阵见血,而且很有逻辑性。接下来我会提出我的观点,你需要做的就是针锋相对地反驳我'}]
28
  chat_transcript = ""
29
  def transcribe(audio):
30
  global messages
31
  global chat_transcript
32
+ global speech_synthesizer
33
  myfile=Path(audio)
34
  myfile=myfile.rename(myfile.with_suffix('.wav'))
35
  audio_file = open(myfile,"rb")
 
43
  # print(response)
44
  messages.append(system_message)
45
 
46
+ speech_synthesis_result = speech_synthesizer.speak_text_async(system_message['content']).get()
47
 
48
+ # 原windows tts 解决方案 subprocess.call(["wsay", system_message['content']])
49
 
50
  chat_transcript = ""
51
  for message in messages:
 
70
  with gr.Blocks(css="#chatbot{height:300px} .overflow-y-auto{height:500px}") as init:
71
  with gr.Row():
72
  api_key = gr.Textbox(
73
+ lines=1, placeholder="api_key Here...", label="api_key",value="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")
74
  style = gr.Textbox(
75
  lines=1, placeholder="style Here...", label="辩风" ,value="你是一名逻辑性很强的资深辩手,你擅长通过数据论据和学理论据来反驳,你的反驳总是一阵见血,而且很有逻辑性。接下来我会提出我的观点,你需要做的就是针锋相对地反驳我,每次回答不超过100个字")
76
  btn = gr.Button(value="初始化")
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
  gradio==3.44.0
2
  openai==0.28.0
3
- pyttsx3==2.90
 
1
  gradio==3.44.0
2
  openai==0.28.0
3
+ azure-cognitiveservices-speech==1.32.1