DavidLiu 3 luni în urmă
părinte
comite
a03dc51a2e
1 a modificat fișierele cu 12 adăugiri și 12 ștergeri
  1. 12 12
      src/core/voip/bot.py

+ 12 - 12
src/core/voip/bot.py

@@ -52,7 +52,7 @@ class UserStatus(Enum):
 
 
 class MyAudioMediaPort(pj.AudioMediaPort):
-    def __init__(self, call, aud_media=None, asr=None):
+    def __init__(self, call, audio_media=None, asr=None):
         pj.AudioMediaPort.__init__(self)
         # # 打开一个 .pcm 文件来保存音频流(可选:保存为 .wav)
         # self.wav = wave.open(f"{recording_file}", "wb")
@@ -61,7 +61,7 @@ class MyAudioMediaPort(pj.AudioMediaPort):
         # self.wav.setframerate(16000)
         print("MyAudioMediaPort::come in, debugger")
         self.call = call
-        self.aud_media = aud_media
+        self.audio_media = audio_media
         self.asr = asr
         self.first = True
 
@@ -186,7 +186,7 @@ class MyCall(pj.Call):
         self.user_part = user_part
         self.call_id = call_id
         self.kwargs = kwargs
-        self.aud_media = None
+        self.audio_media = None
         self.audio_port = None
         self.audio_player = None
         self.asr = None
@@ -295,7 +295,7 @@ class MyCall(pj.Call):
             if media.type == pj.PJMEDIA_TYPE_AUDIO and \
                (media.status == pj.PJSUA_CALL_MEDIA_ACTIVE):
                 self.logger.info("Call Media state 111: %s", call_info.stateText)
-                self.aud_media = self.getAudioMedia(media.index)
+                self.audio_media = self.getAudioMedia(media.index)
                 try:
                     # 建立双向通道
                     self.receive_user_speaker()
@@ -304,9 +304,9 @@ class MyCall(pj.Call):
                     traceback.print_exc()
 
     def receive_user_speaker(self):
-        self.audio_port = MyAudioMediaPort(self, self.aud_media, self.asr)
+        self.audio_port = MyAudioMediaPort(self, self.audio_media, self.asr)
         self.audio_port.createPort("Incoming Call Port", build_audio_format())
-        self.aud_media.startTransmit(self.audio_port)
+        self.audio_media.startTransmit(self.audio_port)
 
     def send_bot_speaker(self, player_file):
         if not player_file :
@@ -315,10 +315,10 @@ class MyCall(pj.Call):
         self.player_complete_dict[player_id] = False
         # print('self.player_complete_dict[player_id]D:', player_id, player_file, self.player_complete_dict[player_id])
         self.logger.info(f"[DEBUG] Sending bot speaker, player_file: {player_file}, player_id: {player_id}")
-        self.audio_player = MyAudioMediaPlayer(player_id, self.aud_media, on_complete=self.on_media_player_complete)
+        self.audio_player = MyAudioMediaPlayer(player_id, self.audio_media, on_complete=self.on_media_player_complete)
         # self.audio_player.createPlayer(player_file[0], pj.PJMEDIA_FILE_NO_LOOP)
         self.audio_player.createPlaylist(player_file, f'my_hello_playlist{player_id}', pj.PJMEDIA_FILE_NO_LOOP)
-        self.audio_player.startTransmit(self.aud_media)
+        self.audio_player.startTransmit(self.audio_media)
 
     def on_receiver_asr_result(self, message, *args):
         # 判断是否播放完成 否则不记录用户说的内容
@@ -375,25 +375,25 @@ class MyCall(pj.Call):
         self.logger.info('liuwei::debugger::release:: come in ')
         if self.audio_player:
             try:
-                self.audio_player.stopTransmit(self.aud_media)
+                self.audio_player.stopTransmit(self.audio_media)
                 print("Success to stopTransmit:")
             except pj.Error as e:
                 print("Failed to stopTransmit:", e)
             self.audio_player = None  # 或调用播放器停止方法
         if self.audio_port:
             try:
-                self.aud_media.stopTransmit(self.audio_port)
+                self.audio_media.stopTransmit(self.audio_port)
                 print("Success to stopTransmit:")
             except pj.Error as e:
                 print("Failed to stopTransmit:", e)
             self.audio_port = None  # 或调用相关销毁方法
-        if self.aud_media:
+        if self.audio_media:
             try:
                 self.audio_media.stopTransmit()
                 print("Success to stopTransmit:")
             except pj.Error as e:
                 print("Failed to stopTransmit:", e)
-            self.aud_media = None
+            self.audio_media = None
 
         self.asr.close()
         # 远程挂机之后要将分机号回收