]> marstr Code Repo - Pilot2AWS/commitdiff
Added background noise and adjusted sample rates for improved realism and immersion. master
authorMarStr <marcus@marstr.online>
Sun, 21 Jul 2024 20:47:18 +0000 (22:47 +0200)
committerMarStr <marcus@marstr.online>
Sun, 21 Jul 2024 20:47:18 +0000 (22:47 +0200)
LICENSE [new file with mode: 0644]
Pilot2AWS.py
endclick.wav [new file with mode: 0644]
repoinfo

diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
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.
index 87cfd92c1bb39dd507f5ccca5e344b518b237ebd..742dcbbce23be6c52fe4f6c4d9c84e81f85073fd 100644 (file)
@@ -1,6 +1,8 @@
 \r
 \r
-import boto3        # pip install boto3\r
-import pygame       # pip install pygame\r
+import boto3                        # pip install boto3\r
+import pygame                       # pip install pygame\r
+import numpy as np                  # pip install numpy\r
+from scipy.io.wavfile import write  # pip install scipy\r
 import time\r
 import io\r
 import random\r
 import time\r
 import io\r
 import random\r
@@ -39,7 +41,7 @@ atc_aws_voicemodel = 'standard'
 # This file can be anywhere and have any name - just make sure you\r
 # put in the correct absolute path into this variable.\r
 # -------------------------------------------------------------------\r
 # This file can be anywhere and have any name - just make sure you\r
 # put in the correct absolute path into this variable.\r
 # -------------------------------------------------------------------\r
-atc_pilot2atc_log = "C:\\Users\\Marcus\\Desktop\\ConversationText.txt"\r
+atc_pilot2atc_log = "M:\\Developer\\Projects\\Pilot2AWS\\test.txt"\r
 \r
 \r
 # -------------------------------------------------------------------\r
 \r
 \r
 # -------------------------------------------------------------------\r
@@ -87,6 +89,9 @@ atc_last_line = -1
 pygame.init()\r
 pygame.mixer.init()\r
 \r
 pygame.init()\r
 pygame.mixer.init()\r
 \r
+# The click at the end of a transmission\r
+click = pygame.mixer.Sound("endclick.wav")\r
+\r
 # Open file before main loop\r
 atc_log = open(atc_pilot2atc_log)\r
 \r
 # Open file before main loop\r
 atc_log = open(atc_pilot2atc_log)\r
 \r
@@ -110,15 +115,41 @@ while True:
 \r
                 # Generate voice!\r
                 # Let's keep it at OGG - best compromize between data transfer size and quality\r
 \r
                 # Generate voice!\r
                 # Let's keep it at OGG - best compromize between data transfer size and quality\r
-                response = atc_polly_client.synthesize_speech(VoiceId=atc_voices[voice_to_use], OutputFormat='ogg_vorbis', Text = line, Engine = atc_aws_voicemodel)\r
+                # Also, added 8Khz as sample frequency to make this sound more authentic\r
+                response = atc_polly_client.synthesize_speech(VoiceId=atc_voices[voice_to_use], OutputFormat='ogg_vorbis', Text = line, Engine = atc_aws_voicemodel, SampleRate="8000")\r
                 # And place that into a binary block\r
                 data = io.BytesIO(response['AudioStream'].read())\r
                 # And place that into a binary block\r
                 data = io.BytesIO(response['AudioStream'].read())\r
+                with open("atc.ogg", 'wb') as f:\r
+                    f.write(data.getbuffer())\r
+                \r
+                # Get length of spoken audio.\r
+                t = pygame.mixer.Sound("atc.ogg")\r
+                l = int(t.get_length()) + 1\r
+                # OK. Generate white noise:\r
+                noise = np.random.normal(0, 1, 8000 * l)\r
+                # Normalize the white noise\r
+                noise = noise / np.max(np.abs(noise))\r
+                # Convert the white noise to a 16-bit format\r
+                noise = (noise * 2**15).astype(np.int16)\r
+                # Save that file too\r
+                write('noise.wav', 8000, noise)\r
+\r
+                # Place Polly's audio in Channel 0\r
+                #pygame.mixer.music.load(data)\r
+                #pygame.mixer.music.play()\r
+                pygame.mixer.Channel(0).play(t)\r
+                \r
+                # Set white noise volume to 10%\r
+                pygame.mixer.Channel(1).set_volume(0.05)\r
+                # Place white noise in Channel 1\r
+                pygame.mixer.Channel(1).play(pygame.mixer.Sound('noise.wav'))\r
+\r
+                while pygame.mixer.Channel(0).get_busy():\r
+                    time.sleep(0.1)\r
+                \r
+                pygame.mixer.Channel(2).set_volume(0.3)\r
+                pygame.mixer.Channel(2).play(click)\r
 \r
 \r
-                # Place the data into pygame and play it\r
-                pygame.mixer.music.load(data)\r
-                pygame.mixer.music.play()\r
-                pygame.event.wait()\r
-        \r
         # Increase loop count\r
         idx = idx + 1\r
 \r
         # Increase loop count\r
         idx = idx + 1\r
 \r
diff --git a/endclick.wav b/endclick.wav
new file mode 100644 (file)
index 0000000..01d9ec8
Binary files /dev/null and b/endclick.wav differ
index 3836acc310b0ebc0d0a17c83a3b5b7d7cf63b4c3..cbe4da91173c01d7b9b894640a9cc60ad414fc81 100644 (file)
--- a/repoinfo
+++ b/repoinfo
@@ -2,6 +2,8 @@
 \r
 A Python script allowing to use standard or neural voices of Amazon Polly, in Pilot2ATC. It does so by monitoring Pilot2ATC's output and leveraging Amazon's Polly technology, to generate voice responses that sound more natural.\r
 \r
 \r
 A Python script allowing to use standard or neural voices of Amazon Polly, in Pilot2ATC. It does so by monitoring Pilot2ATC's output and leveraging Amazon's Polly technology, to generate voice responses that sound more natural.\r
 \r
+Now with added immersion as the result sounds very much like an actual radio transmission, including background noise.\r
+\r
 The voices that Pilot2ATC can use are those that are available on your system, on Windows this set is usually extremely limited. On top of that, they sound very robotic. Not what you'd want when talking to ATC in a flight. While there are solutions available that leverage AI (custom versions of ChatGPT), the costs are - in my opinion - too high. SayIntentions is my prime example. Clocking in at 30 Dollars per month (at the time of this writing), it is deemed not feasible for most.\r
 \r
 I did have a look at ChatGPT itself for ATC, and other available tools. I came to the conclusion that Pilot2ATC is the best currently available. It does cost 55 Euros - but it is a one-off payment, you get to keep the tool forever.\r
 The voices that Pilot2ATC can use are those that are available on your system, on Windows this set is usually extremely limited. On top of that, they sound very robotic. Not what you'd want when talking to ATC in a flight. While there are solutions available that leverage AI (custom versions of ChatGPT), the costs are - in my opinion - too high. SayIntentions is my prime example. Clocking in at 30 Dollars per month (at the time of this writing), it is deemed not feasible for most.\r
 \r
 I did have a look at ChatGPT itself for ATC, and other available tools. I came to the conclusion that Pilot2ATC is the best currently available. It does cost 55 Euros - but it is a one-off payment, you get to keep the tool forever.\r
@@ -43,10 +45,12 @@ If you want to use AWS and its services elsewhere, you are of course free to ins
 \r
 [section]Setup[/section]\r
 \r
 \r
 [section]Setup[/section]\r
 \r
-You will need two Python modules: boto3 and pygame. Install them like so:\r
+You will need four Python modules: pygame, boto3, numpy and scipy. Install them like so:\r
 \r
 [code]pip install boto3\r
 \r
 [code]pip install boto3\r
-pip install pygame[/code]\r
+pip install pygame\r
+pip install numpy\r
+pip install scipy[/code]\r
 \r
 Next, open up the Pilot2AWS.py script with your favorite editor and make the necessary adjustments as follows:\r
 \r
 \r
 Next, open up the Pilot2AWS.py script with your favorite editor and make the necessary adjustments as follows:\r
 \r
@@ -131,5 +135,6 @@ The sound format is OGG Vorbis. I would recommend you to leave it at that. It is
 I may need to figure out how to efficiently read X-Plane's dataref values so that I can further enhance realism. For example only pick another voice if you left a certain area or changed the type of contact. I will be looking into this at some time - for now I am happy with how this has turned out.\r
 \r
 \r
 I may need to figure out how to efficiently read X-Plane's dataref values so that I can further enhance realism. For example only pick another voice if you left a certain area or changed the type of contact. I will be looking into this at some time - for now I am happy with how this has turned out.\r
 \r
 \r
-[History]\r
+[section]History[/section]\r
+v1.02 - Implemented mechanism that generates 8kHz white noise, and change to generate the voice also with 8kHz. Implemented code to mix both sounds together\r
 v1.01 - Updated loop mechanism for more efficiency and accuracy\r
 v1.01 - Updated loop mechanism for more efficiency and accuracy\r