Skip to content

Commit 96243c3

Browse files
all_Automation_Git_Actions
1 parent 252360f commit 96243c3

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

allAutomation/.idea/workspace.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

allAutomation/my_project/tests/microphoneSimulationTest.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,37 @@ def test_microphone_simulation(setup):
110110

111111

112112
def play_audio_through_microphone(audio_file):
113+
# Get the absolute path to the audio file
114+
audio_file_path = os.path.join(os.path.dirname(__file__), 'path_to_audio_directory', audio_file)
115+
116+
# Check if the file exists
117+
if not os.path.exists(audio_file_path):
118+
raise FileNotFoundError(f"File '{audio_file}' not found at '{audio_file_path}'")
119+
113120
chunk = 1024
114-
wf = wave.open(audio_file, 'rb')
121+
wf = wave.open(audio_file_path, 'rb')
115122

116123
p = pyaudio.PyAudio()
117124

125+
# Configure stream for input (microphone)
118126
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
119127
channels=wf.getnchannels(),
120128
rate=wf.getframerate(),
121-
input=True, # Specify input=True for input stream
129+
input=True, # Set to True for input stream (microphone)
122130
frames_per_buffer=chunk)
123131

124132
data = wf.readframes(chunk)
125133

126134
while data:
135+
# Write data to the input stream (microphone)
127136
stream.write(data)
128137
data = wf.readframes(chunk)
129138

139+
# Stop and close the input stream
130140
stream.stop_stream()
131141
stream.close()
142+
143+
# Terminate PyAudio
132144
p.terminate()
133145

134146

0 commit comments

Comments
 (0)