Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
Fix issues for cloning voice feature (#562)
Browse files Browse the repository at this point in the history
Signed-off-by: Lv, Liang1 <liang1.lv@intel.com>
  • Loading branch information
lvliang-intel authored Oct 30, 2023
1 parent 6446dab commit d540131
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#################################################################################
# SERVER SETTING #
#################################################################################
host: 127.0.0.1
host: 0.0.0.0
port: 8888

model_name_or_path: "Intel/neural-chat-7b-v1-1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#################################################################################
# SERVER SETTING #
#################################################################################
host: 127.0.0.1
host: 0.0.0.0
port: 8000

model_name_or_path: "starcoder_int8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def stream_text2speech(self, generator, output_audio_path, voice="default"):


def post_llm_inference_actions(self, text_or_generator):
from intel_extension_for_transformers.neural_chat.plugins import plugins
self.voice = plugins.tts.args["voice"]
if self.stream_mode:
def cache_words_into_sentences():
buffered_texts = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from fastapi import File, UploadFile, Form
from pydub import AudioSegment
from ...config import GenerationConfig
from ...plugins import plugins
import base64
import torch

Expand All @@ -47,9 +48,10 @@ def handle_voice_asr_request(self, filename: str) -> str:
except Exception as e:
raise Exception(e)

async def handle_voice_chat_request(self, prompt: str, audio_output_path: Optional[str]=None) -> str:
async def handle_voice_chat_request(self, prompt: str, voice: str, audio_output_path: Optional[str]=None) -> str:
chatbot = self.get_chatbot()
try:
plugins.tts.args["voice"] = voice
config = GenerationConfig(audio_output_path=audio_output_path)
result, link = chatbot.chat_stream(query=prompt, config=config)
def audio_file_generate(result):
Expand Down Expand Up @@ -90,6 +92,7 @@ async def handle_talkingbot_asr(file: UploadFile = File(...)):
audio = AudioSegment.from_file("tmp_audio_bytes")
audio = audio.set_frame_rate(16000)
# bytes to wav
file_name = file_name +'.wav'
audio.export(f"{file_name}", format="wav")
asr_result = router.handle_voice_asr_request(file_name)
return {"asr_result": asr_result}
Expand All @@ -105,7 +108,7 @@ async def talkingbot(request: Request):

logger.info(f'Received prompt: {text}, and use voice: {voice} knowledge_id: {knowledge_id}')

return await router.handle_voice_chat_request(text, audio_output_path)
return await router.handle_voice_chat_request(text, voice, audio_output_path)

@router.post("/v1/talkingbot/create_embedding")
async def create_speaker_embedding(file: UploadFile = File(...)):
Expand All @@ -120,5 +123,5 @@ async def create_speaker_embedding(file: UploadFile = File(...)):
audio = AudioSegment.from_file(f"tmp_spk_{file_name}")
audio.export(f"{spk_id}", format="mp3")

router.handle_create_speaker_embedding(spk_id)
await router.handle_create_speaker_embedding(spk_id)
return {"spk_id": spk_id}

0 comments on commit d540131

Please sign in to comment.