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
hey here is my code
import logging
from pyVoIP.VoIP import VoIPPhone, CallState
import speech_recognition as sr
import uuid
import pywav
from pydub import AudioSegment
import os
import shutil
import time
Set up logging
logging.basicConfig(
level=logging.DEBUG, # Log all levels (DEBUG, INFO, WARNING, ERROR, CRITICAL)
format='%(asctime)s - %(levelname)s - %(message)s', # Log format
handlers=[
logging.FileHandler("voip_log.log"), # Save logs to a file
logging.StreamHandler() # Also output logs to the console
]
)
ffmpeg_path = shutil.which("ffmpeg")
if ffmpeg_path:
logging.info(f"FFmpeg found at: {ffmpeg_path}")
else:
logging.error("FFmpeg not found in PATH")
try:
# Create a simple test audio file if it doesn't exist
if not os.path.exists("test.wav"):
from pydub.generators import Sine
sound = Sine(440).to_audio_segment(duration=5000) # 1-second tone
sound.export("test.wav", format="wav")
logging.info("Test audio file 'test.wav' created.")
test_audio = AudioSegment.from_file("test.wav")
logging.info("FFmpeg is correctly configured.")
except Exception as e:
logging.error(f"Error with FFmpeg configuration: {e}")
def convert_to_wav(audio, tmpFileName):
try:
data_bytes = b"".join(audio)
wave_write = pywav.WavWrite(tmpFileName, 1, 8000, 8, 7)
wave_write.write(data_bytes)
wave_write.close()
logging.info(f"Audio converted to WAV and saved as {tmpFileName}")
return tmpFileName
except Exception as e:
logging.error(f"Error converting audio to WAV: {e}")
return None
def transcribe_to_text(audio_file):
recognizer = sr.Recognizer()
try:
# Load the .wav audio file and recognize speech using Sphinx
with sr.AudioFile(audio_file) as source:
audio = recognizer.record(source)
# Use the offline Sphinx recognizer
transcription = recognizer.recognize_sphinx(audio)
logging.info(f"Transcription successful: {transcription}")
return transcription
except sr.UnknownValueError:
logging.warning("Sphinx could not understand the audio.")
except sr.RequestError as e:
logging.error(f"Sphinx error; {e}")
return ""
while vp._status == 'REGISTERING':
time.sleep(5)
logging.info(f"Phone is still registering... Current state: {vp._status}")
Check if the phone is successfully registered
if vp._status == 'REGISTERED':
logging.info(f"Phone successfully registered with status: {vp._status}")
else:
logging.error(f"Phone failed to register. Current status: {vp._status}")
input("Press any key to exit the VOIP phone session.")
vp.stop()
logging.info("VOIP phone session stopped.")
when i run this at show eh this error 2024-09-11 17:45:46,172 - INFO - FFmpeg found at: /usr/bin/ffmpeg
2024-09-11 17:45:46,172 - INFO - FFmpeg is correctly configured.
2024-09-11 17:45:46,313 - ERROR - Phone failed to register. Current status: PhoneStatus.REGISTERING
Press any key to exit the VOIP phone session.TODO: Add 500 Error on Receiving SIP Response
The text was updated successfully, but these errors were encountered:
hey here is my code
import logging
from pyVoIP.VoIP import VoIPPhone, CallState
import speech_recognition as sr
import uuid
import pywav
from pydub import AudioSegment
import os
import shutil
import time
Set up logging
logging.basicConfig(
level=logging.DEBUG, # Log all levels (DEBUG, INFO, WARNING, ERROR, CRITICAL)
format='%(asctime)s - %(levelname)s - %(message)s', # Log format
handlers=[
logging.FileHandler("voip_log.log"), # Save logs to a file
logging.StreamHandler() # Also output logs to the console
]
)
ffmpeg_path = shutil.which("ffmpeg")
if ffmpeg_path:
logging.info(f"FFmpeg found at: {ffmpeg_path}")
else:
logging.error("FFmpeg not found in PATH")
try:
# Create a simple test audio file if it doesn't exist
if not os.path.exists("test.wav"):
from pydub.generators import Sine
sound = Sine(440).to_audio_segment(duration=5000) # 1-second tone
sound.export("test.wav", format="wav")
logging.info("Test audio file 'test.wav' created.")
except Exception as e:
logging.error(f"Error with FFmpeg configuration: {e}")
def convert_to_wav(audio, tmpFileName):
try:
data_bytes = b"".join(audio)
wave_write = pywav.WavWrite(tmpFileName, 1, 8000, 8, 7)
wave_write.write(data_bytes)
wave_write.close()
logging.info(f"Audio converted to WAV and saved as {tmpFileName}")
return tmpFileName
except Exception as e:
logging.error(f"Error converting audio to WAV: {e}")
return None
def transcribe_to_text(audio_file):
recognizer = sr.Recognizer()
try:
# Load the .wav audio file and recognize speech using Sphinx
with sr.AudioFile(audio_file) as source:
audio = recognizer.record(source)
# Use the offline Sphinx recognizer
transcription = recognizer.recognize_sphinx(audio)
logging.info(f"Transcription successful: {transcription}")
return transcription
except sr.UnknownValueError:
logging.warning("Sphinx could not understand the audio.")
except sr.RequestError as e:
logging.error(f"Sphinx error; {e}")
return ""
def answer(call):
try:
call.answer()
logging.info("Call answered.")
buffer = []
buff_length = 0
vp = VoIPPhone('ip', 5060, 'phone name', 'passowrd', callCallback=answer)
vp.start()
while vp._status == 'REGISTERING':
time.sleep(5)
logging.info(f"Phone is still registering... Current state: {vp._status}")
Check if the phone is successfully registered
if vp._status == 'REGISTERED':
logging.info(f"Phone successfully registered with status: {vp._status}")
else:
logging.error(f"Phone failed to register. Current status: {vp._status}")
input("Press any key to exit the VOIP phone session.")
vp.stop()
logging.info("VOIP phone session stopped.")
when i run this at show eh this error 2024-09-11 17:45:46,172 - INFO - FFmpeg found at: /usr/bin/ffmpeg
2024-09-11 17:45:46,172 - INFO - FFmpeg is correctly configured.
2024-09-11 17:45:46,313 - ERROR - Phone failed to register. Current status: PhoneStatus.REGISTERING
Press any key to exit the VOIP phone session.TODO: Add 500 Error on Receiving SIP Response
The text was updated successfully, but these errors were encountered: