ming il y a 3 ans
Parent
commit
96d8aef0e0

+ 9 - 4
OpenshotService/hakkaUtil.py

@@ -128,8 +128,13 @@ def import_jieba_userdict(ch_word_list, userDict_path='userDict.txt'):
   jieba.load_userdict(userDict_path)
   return jieba
 
-def gen_hakka_tts(word_data,multi_sound,hakka_100,ch_sentence,mp3_path='test1.mp3',verbose=0):
+def gen_hakka_tts(word_data,multi_sound,hakka_100,ch_sentence,mp3_path='test1.mp3',gender,verbose=0):
   Y = []
+  pitch_step = 0
+  if gender == 0:
+    pitch_step=8
+  else:
+    pitch_step=0
   print(jieba.lcut(ch_sentence))
   for word in jieba.lcut(ch_sentence):
     tmp_mapping_100 = hakka_100.loc[[word == i for i in hakka_100.chinese_clean],:].head(1)
@@ -143,14 +148,14 @@ def gen_hakka_tts(word_data,multi_sound,hakka_100,ch_sentence,mp3_path='test1.mp
         if tmp_mapping.index[0] in list(multi_sound.index):
           y, sr = librosa.load('mp3_uni/{}.mp3'.format(tmp_mapping.index[0]))
           if tmp_mapping.gender.values[0] == 'Male':
-            y = librosa.effects.pitch_shift(y, sr, n_steps=8)
+            y = librosa.effects.pitch_shift(y, sr, n_steps=pitch_step)
         else:
           y, sr = librosa.load('mp3/{}.mp3'.format(tmp_mapping.index[0]))
           if tmp_mapping.gender.values[0] == 'Male':
-            y = librosa.effects.pitch_shift(y, sr, n_steps=8)
+            y = librosa.effects.pitch_shift(y, sr, n_steps=pitch_step)
         Y += list(y[abs(y)>0.0005])
     else:
       y, sr = librosa.load('mp3_uni/hakka_100_{}.mp3'.format(tmp_mapping_100.index[0]))
-      y = librosa.effects.pitch_shift(y, sr, n_steps=4)
+      y = librosa.effects.pitch_shift(y, sr, n_steps=pitch_step)
       Y += list(y[abs(y)>0.0005])
   librosa.output.write_wav(mp3_path, np.array(Y), sr)

+ 5 - 4
OpenshotService/openshot_video_generator.py

@@ -135,7 +135,7 @@ def make_dir(name_hash):
     except FileExistsError:
         print("~~~~~~Warning~~~~~~~~~Directory " , dir_subtitle+name_hash ,  " already exists")
 
-def hakkaTTS(mp3_path,ch_sentence):
+def hakkaTTS(mp3_path,ch_sentence,gender):
     download = False #如果要下載才需要Ture
     hakka_100 = import_hakka_100()
     word_data,multi_sound = import_data()
@@ -144,7 +144,7 @@ def hakkaTTS(mp3_path,ch_sentence):
         download_hakka_100(hakka_100)
     ch_word_list = list(itertools.chain(*word_data['華語詞義集'].tolist())) + hakka_100.chinese_clean.tolist()
     import_jieba_userdict(ch_word_list=ch_word_list, userDict_path='userDict.txt')
-    gen_hakka_tts(word_data,multi_sound,hakka_100,ch_sentence,mp3_path)
+    gen_hakka_tts(word_data,multi_sound,hakka_100,ch_sentence,mp3_path,gender)
 
 
 def file_prepare(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
@@ -175,8 +175,9 @@ def file_prepare(name, name_hash,text_content,image_urls,multiLang,lang='zh'):
     txt_idx = 0
     for txt in text_content:
         if multiLang==3:
-            hakkaTTS(dir_sound+name_hash+"/"+str(txt_idx)+".mp3",txt)
-        else:
+            hakkaTTS(dir_sound+name_hash+"/"+str(txt_idx)+".mp3",txt,0)
+        elif mulitLang==4:
+            hakkaTTS(dir_sound+name_hash+"/"+str(txt_idx)+".mp3",txt,1)
             if lang!='zh' or multiLang==1:
                 if lang!='zh':
                     tts = gTTS(txt)

+ 4 - 0
api/static/script_util.js

@@ -141,6 +141,10 @@ $(".next").click(function () {
   multiLang = 0
   if ($('#multiLang').prop("checked")) {multiLang = 1;}
   if ($('#hakka_in').prop("checked")) {multiLang=3;}
+  if(avatar==99)
+  {
+    multiLang=4;
+  }
   dataOBJ = { "name": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar,"multiLang":multiLang, "client_id": client_id }
   objstr = JSON.stringify(dataOBJ);
   console.log(dataOBJ)

+ 7 - 0
api/templates/make_video.html

@@ -39,6 +39,7 @@
               <option value="17">客語人員1</option>
               <option value="18">客語人員2</option>
               <option value="19">客語人員3</option>
+              <option value="99">Jared</option>
               <option value="7">Peggy</option>
               <option value="8">Stacy</option>
               <option value="10">Nina黑</option>
@@ -64,6 +65,12 @@
                   <h5 class="card-title">客語人員3</h5>
                 </div>
               </div>
+              <div class="card item" data-avatar="Peggy" data-img="peggy">
+                <div class="imgfr"><img src="static/img/peggy.webp" class="card-img-top" alt="..."></div>
+                <div class="card-body">
+                  <h5 class="card-title">Jared</h5>
+                </div>
+              </div>
               <div class="card item" data-avatar="Peggy" data-img="peggy">
                 <div class="imgfr"><img src="static/img/peggy.webp" class="card-img-top" alt="..."></div>
                 <div class="card-body">