Phonograph, refers to cylinder record playing devices although in the USA, phonograph is a generic term for both types. Gramophone refers specifically to devices that play flat disc records

Thomas Alva Edison was America's greatest inventor and businessman. In 1877 he produced the very first machine to record and reproduce sound. The Phonograph.

The science of the recording of sound went as far back as 1857.
Édouard-Léon Scott de Martinville invented the earliest known sound recording device, the Phonautograph, which was patented in France on 25 March 1857. The Phonautograph used a horn attached to a diaphragm to collect sound. This vibrated a stiff bristle which inscribed an image on a lamp black coated, hand-cranked cylinder. It only created visual images of the sound and did not have the ability to play back its recordings.

Charles Cros was a French poet and inventor. (Here is one of his poems sung by Brigette Bardot). On 30 April 1877, inspired by the Phonautograph, he submitted a sealed envelope containing a letter to the Academy of Sciences in Paris explaining his proposed method of playing back recorded sound. He named his invention the Paleophone. An article on the Paleophone was published in "la semaine du Clergé", on October 10, 1877, where its author even renamed it the Phonograph. (The French argue, what are the odds of Edison coming up with the exact same invention and the exact same name for it only a few months after this publication. In 1877 it took a ship between 7 and 8 days to cross the Atlantic.)
Cros’s method took the Phonautograph principal of recording sound, together with a well-known photo-etching process to make a permanent record which could be played again on the same recording machine. (The etching process was later used by Berliner to make masters of his flat disc recordings). Cros's work remained a theory. He did not produce a working model of it.

Thomas Edison. Sometime in late 1877, Edison gave a sketch of his phonograph to his machinist, John Kruesi, to build. On completion, Edison immediately tested the machine by speaking a nursery rhyme - "Mary had a little lamb"- into the mouthpiece. To his amazement, the machine played his words back to him.

It was later stated that the date for this event was on August 12, 1877. Some historians believe that it probably happened several months later, since Edison did not file for a patent until December 24, 1877. Edison's aide, Charles Batchelor, in his diary, confirmed that the Kruesi phonograph was constructed on December 4, and finished two days later. In any case, Edison did construct the first working phonograph for recording and playing back sound. Edison soon stopped working on the phonograph, focusing instead on improving the light bulb.

Here is a link to the NPS site with an in-depth symposium on The Origins of Sound Recording. Excellent set of videos, starting with this one. Edison’s Path to the Phonograph

It was not until almost 10 years later, on May 4, 1886, that Chichester Bell (Alexander’s cousin) and Charles Sumner Tainter patented their Graphophone. The Graphophone used a wax cylinder instead of tin-foil and a floating reproducer instead of a rigid stylus. The improvements were astounding and marketable machines were produced. Initially dictation machines were produced for businesses by The Volta Graphophone Company later renamed The American Graphophone. Combined they later evolved into Columbia Records. They abandoned the cylinder market in 1912, preferring to concentrate on the more reliable Berliner flat disc record.

Edison, annoyed that his invention was being hijacked by competitors, restarted work on his Phonograph. The Edison Phonograph Company was formed on October 8, 1887, to market Edison's New Improved Phonograph, which was introduced in May 1888. It used wax cylinders and a floating reproducer. Constant improvements were made over the next few decades and a huge range of Edison phonographs were produced. The last of these were produced in 1929.