From 7752034d2fd452216995059a3bfa063dd1447ad0 Mon Sep 17 00:00:00 2001 From: MarStr Date: Sun, 21 Jul 2024 22:47:18 +0200 Subject: [PATCH] Added background noise and adjusted sample rates for improved realism and immersion. --- LICENSE | 21 +++++++++++++++++++++ Pilot2AWS.py | 49 ++++++++++++++++++++++++++++++++++++++++--------- endclick.wav | Bin 0 -> 2484 bytes repoinfo | 11 ++++++++--- 4 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 LICENSE create mode 100644 endclick.wav diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8aa2645 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [year] [fullname] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Pilot2AWS.py b/Pilot2AWS.py index 87cfd92..742dcbb 100644 --- a/Pilot2AWS.py +++ b/Pilot2AWS.py @@ -1,6 +1,8 @@ -import boto3 # pip install boto3 -import pygame # pip install pygame +import boto3 # pip install boto3 +import pygame # pip install pygame +import numpy as np # pip install numpy +from scipy.io.wavfile import write # pip install scipy import time import io import random @@ -39,7 +41,7 @@ atc_aws_voicemodel = 'standard' # This file can be anywhere and have any name - just make sure you # put in the correct absolute path into this variable. # ------------------------------------------------------------------- -atc_pilot2atc_log = "C:\\Users\\Marcus\\Desktop\\ConversationText.txt" +atc_pilot2atc_log = "M:\\Developer\\Projects\\Pilot2AWS\\test.txt" # ------------------------------------------------------------------- @@ -87,6 +89,9 @@ atc_last_line = -1 pygame.init() pygame.mixer.init() +# The click at the end of a transmission +click = pygame.mixer.Sound("endclick.wav") + # Open file before main loop atc_log = open(atc_pilot2atc_log) @@ -110,15 +115,41 @@ while True: # Generate voice! # Let's keep it at OGG - best compromize between data transfer size and quality - response = atc_polly_client.synthesize_speech(VoiceId=atc_voices[voice_to_use], OutputFormat='ogg_vorbis', Text = line, Engine = atc_aws_voicemodel) + # Also, added 8Khz as sample frequency to make this sound more authentic + response = atc_polly_client.synthesize_speech(VoiceId=atc_voices[voice_to_use], OutputFormat='ogg_vorbis', Text = line, Engine = atc_aws_voicemodel, SampleRate="8000") # And place that into a binary block data = io.BytesIO(response['AudioStream'].read()) + with open("atc.ogg", 'wb') as f: + f.write(data.getbuffer()) + + # Get length of spoken audio. + t = pygame.mixer.Sound("atc.ogg") + l = int(t.get_length()) + 1 + # OK. Generate white noise: + noise = np.random.normal(0, 1, 8000 * l) + # Normalize the white noise + noise = noise / np.max(np.abs(noise)) + # Convert the white noise to a 16-bit format + noise = (noise * 2**15).astype(np.int16) + # Save that file too + write('noise.wav', 8000, noise) + + # Place Polly's audio in Channel 0 + #pygame.mixer.music.load(data) + #pygame.mixer.music.play() + pygame.mixer.Channel(0).play(t) + + # Set white noise volume to 10% + pygame.mixer.Channel(1).set_volume(0.05) + # Place white noise in Channel 1 + pygame.mixer.Channel(1).play(pygame.mixer.Sound('noise.wav')) + + while pygame.mixer.Channel(0).get_busy(): + time.sleep(0.1) + + pygame.mixer.Channel(2).set_volume(0.3) + pygame.mixer.Channel(2).play(click) - # Place the data into pygame and play it - pygame.mixer.music.load(data) - pygame.mixer.music.play() - pygame.event.wait() - # Increase loop count idx = idx + 1 diff --git a/endclick.wav b/endclick.wav new file mode 100644 index 0000000000000000000000000000000000000000..01d9ec876766abc2056cd762cee79ae9058c8c37 GIT binary patch literal 2484 zcmW+&d017|7GHaxbM6QTiUSUSKKM-KSq_+rIFzEimkNqNs2Pqp;#_7bs0nJ0*%J+m zlII-o6iZEw2uqX9(2xXk0y6|I!u6he&OUpu&iB6k-(J5p{npxR?MbmQF{kVRNuv_S z%w4=P)E@wdc}9i+WDEzO;19D?SEgp07=^Y2S)7AY*oadwUk^7{k|a?qB9td2naq?Q z@l#@*94H5oa7a+r&`)t8*~Z=mS=k_dgo#p(bcQYx8XlJ7to`LDI75C_nWdCVw}q9s z$aL6;T}YukM;flYkSlS46kthI(knVu)ZwH(h%l4WrSs}{_y z(gWj=_bkbj7PAVkKdEE)o41jAWv&{{Im|b5j2paYC*`zlbHrEO7!pu)vD%fGYpJfvAGfI6%&#P$)qTFZ@^ZtdY1yVM?@nCrv)xPY zkGei5bl#BapLShIAJQDT^hW%>(tba)eK&jdI~FFcMFe=q7T!rI%O5Zz@Il!)ONZbt zwN$U`mu;%mF5a%jN#k>^Ew3S`k?A%y zO`T0DXlFPt*BYT}Fz?B0`7M$~T}GAK-`IjPF_{;sLE30K(9()w>?R_u7Xf&gF6Ezk zZyP=$hR2bQ;WF!FY-OV%-v{H~^*3@G7P44Sp9eNKQhzvN zxe_$f{oNnE!bn8wL>R=UVgpm)R9}E~hX=9Vbm`yIQMiSnXG4iE9qD4tLnJIV8{d1IvA0AkTKX zgzzla+>YD687$9pMl{jW(ywwoe1i$r?zVDqP;E~J+SiK`o<^I*3EGwfd#~zA@)}yK zbqAZJ7rW2S(^u3f+6DU~@wPhz*3xvGO~*nTBSaj;I%6b>kbL!yY%M*^g?0+Eq++I*cxN2k<5=`71gPZKVmgMZp;$?e4lWLS>9rO7`%q>v;O>B zaYBSkn~YUVwJs2)+JBT&Fcp)f2do2|D#m*ov?I1-&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