You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I have just started using your library in order to create a softphone linked to freepbx and so I tested the calls with an open source softphone (Zoiper) the problem is that you can't hear me. I don't really know how to do it. Here is the code I started in one file.
import asyncio
import tkinter as tk
from tkinter import messagebox
import threading
from PySIP.sip_account import SipAccount
from PySIP.audio_stream import AudioStream # Votre classe AudioStream
class SIPApp:
def init(self, master):
self.master = master
master.title("SIP Connection")
self.label_username = tk.Label(master, text="Username:")
self.label_username.pack()
self.entry_username = tk.Entry(master)
self.entry_username.pack()
self.label_password = tk.Label(master, text="Password:")
self.label_password.pack()
self.entry_password = tk.Entry(master, show="*")
self.entry_password.pack()
self.label_server = tk.Label(master, text="Server (e.g., 192.168.1.201:5060):")
self.label_server.pack()
self.entry_server = tk.Entry(master)
self.entry_server.pack()
self.button_connect = tk.Button(master, text="Connect", command=self.connect)
self.button_connect.pack()
self.label_destination = tk.Label(master, text="Number to Call:")
self.label_destination.pack()
self.entry_destination = tk.Entry(master)
self.entry_destination.pack()
self.button_call = tk.Button(master, text="Call", command=self.make_call)
self.button_call.pack()
self.button_call.config(state=tk.DISABLED) # Disable button initially
self.account = None # SIP Account
self.current_call = None # Current SIP call
# Assurez-vous que l'événement loop est configuré correctement
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
async def connect_sip(self, username, password, server):
self.account = SipAccount(username, password, server)
try:
await asyncio.wait_for(self.account.register(), timeout=10)
messagebox.showinfo("Success", "Connection successful!")
self.button_call.config(state=tk.NORMAL) # Enable call button
except asyncio.TimeoutError:
messagebox.showerror("Error", "Connection timed out after 10 seconds.")
except Exception as e:
messagebox.showerror("Error", f"Connection failed: {e}")
async def call_number(self, number):
try:
self.current_call = self.account.make_call(number)
await self.current_call.start() # Démarrer l'appel SIP
# Après avoir démarré l'appel, vous pouvez démarrer le streaming audio
audio_stream = AudioStream() # Chargez le fichier WAV
# Démarrer un thread séparé pour envoyer l'audio en continu
threading.Thread(target=self.send_audio, args=(audio_stream,)).start()
messagebox.showinfo("Call", f"Calling {number}...")
# Vérifier l'état de l'appel
while True:
await asyncio.sleep(1)
if self.current_call.is_finished():
break
await self.account.unregister()
except Exception as e:
messagebox.showerror("Error", f"Call failed: {e}")
def send_audio(self, audio_stream):
# Cette méthode envoie l'audio dans le flux RTP
audio_stream.recv() # Préparer les trames audio
while True:
frame = audio_stream.input_q.get() # Récupérer la prochaine trame de la file d'attente
if frame is None: # Fin du fichier audio
audio_stream.stream_done() # Marquer le flux comme terminé
break
# Envoyer la trame au flux RTP via PySIP (méthode à implémenter avec PySIP)
self.current_call.send_audio_frame(frame) # Envoyer la trame au flux RTP
def connect(self):
username = self.entry_username.get()
password = self.entry_password.get()
server = self.entry_server.get()
# Démarrer la connexion SIP dans un thread
threading.Thread(target=self.run_async_task, args=(self.connect_sip(username, password, server),)).start()
def make_call(self):
number = self.entry_destination.get()
if self.account:
# Démarrer l'appel SIP dans un thread
threading.Thread(target=self.run_async_task, args=(self.call_number(number),)).start()
def run_async_task(self, coroutine):
asyncio.set_event_loop(self.loop)
self.loop.run_until_complete(coroutine)
if name == "main":
root = tk.Tk()
app = SIPApp(root)
root.mainloop()
I thank you in advance for your return.
Sincerely.
NDev_Z
The text was updated successfully, but these errors were encountered:
Hello, I have just started using your library in order to create a softphone linked to freepbx and so I tested the calls with an open source softphone (Zoiper) the problem is that you can't hear me. I don't really know how to do it. Here is the code I started in one file.
import asyncio
import tkinter as tk
from tkinter import messagebox
import threading
from PySIP.sip_account import SipAccount
from PySIP.audio_stream import AudioStream # Votre classe AudioStream
class SIPApp:
def init(self, master):
self.master = master
master.title("SIP Connection")
if name == "main":
root = tk.Tk()
app = SIPApp(root)
root.mainloop()
I thank you in advance for your return.
Sincerely.
NDev_Z
The text was updated successfully, but these errors were encountered: