|
| 1 | +import requests |
| 2 | +import time |
| 3 | +import os |
| 4 | + |
| 5 | +# Base URL for the REST API (ensure that this is correct) |
| 6 | +BASE_URL = "http://localhost:8011/A2F" |
| 7 | + |
| 8 | +# Path to the audio file you want to load |
| 9 | +audio_file_path = r"C:\Users\paulp\AppData\Local\ov\pkg\deps\b9070d65cb1908ec472cf47bc29f8126\exts\omni.audio2face.player_deps\deps\audio2face-data\tracks\output.wav" |
| 10 | + |
| 11 | +# Function to load the audio file |
| 12 | +def load_audio_file(): |
| 13 | + url = f"{BASE_URL}/USD/Load" |
| 14 | + data = { |
| 15 | + "file_path": audio_file_path |
| 16 | + } |
| 17 | + response = requests.post(url, json=data) |
| 18 | + if response.status_code == 200: |
| 19 | + print("Audio file loaded successfully!") |
| 20 | + else: |
| 21 | + print(f"Failed to load audio file: {response.status_code}") |
| 22 | + |
| 23 | +# Function to play the audio |
| 24 | +def play_audio(): |
| 25 | + url = f"{BASE_URL}/USD/Play" |
| 26 | + response = requests.post(url) |
| 27 | + if response.status_code == 200: |
| 28 | + print("Audio started playing!") |
| 29 | + else: |
| 30 | + print(f"Failed to play audio: {response.status_code}") |
| 31 | + |
| 32 | +# Function to stop the audio |
| 33 | +def stop_audio(): |
| 34 | + url = f"{BASE_URL}/USD/Stop" |
| 35 | + response = requests.post(url) |
| 36 | + if response.status_code == 200: |
| 37 | + print("Audio stopped successfully!") |
| 38 | + else: |
| 39 | + print(f"Failed to stop audio: {response.status_code}") |
| 40 | + |
| 41 | +# Monitor the audio file and reload it when updated |
| 42 | +last_modified_time = None |
| 43 | + |
| 44 | +def monitor_audio_file(): |
| 45 | + global last_modified_time |
| 46 | + |
| 47 | + while True: |
| 48 | + # Check the last modified time of the audio file |
| 49 | + current_modified_time = os.path.getmtime(audio_file_path) |
| 50 | + |
| 51 | + # If the file has been modified, reload and play it |
| 52 | + if last_modified_time is None or current_modified_time > last_modified_time: |
| 53 | + stop_audio() # Stop any existing audio playback |
| 54 | + load_audio_file() # Load the updated audio file |
| 55 | + play_audio() # Play the audio automatically |
| 56 | + last_modified_time = current_modified_time |
| 57 | + |
| 58 | + # Wait 5 seconds before checking again |
| 59 | + time.sleep(5) |
| 60 | + |
| 61 | +# Start monitoring the audio file for changes |
| 62 | +monitor_audio_file() |
0 commit comments